[FunctionAttrs] Volatile loads should disable readonly

A volatile load has side effects beyond what callers expect readonly to
signify.  For example, it is not safe to reorder two function calls
which each perform a volatile load to the same memory location.

llvm-svn: 270671
This commit is contained in:
David Majnemer 2016-05-25 05:53:04 +00:00
parent 7c1841a55e
commit 124bdb7497
2 changed files with 13 additions and 0 deletions

View File

@ -463,6 +463,11 @@ determinePointerReadAttrs(Argument *A,
}
case Instruction::Load:
// A volatile load has side effects beyond what readonly can be relied
// upon.
if (cast<LoadInst>(I)->isVolatile())
return Attribute::None;
IsRead = true;
break;

View File

@ -104,3 +104,11 @@ define <4 x i32> @test12_2(<4 x i32*> %ptrs) {
%res = call <4 x i32> @test12_1(<4 x i32*> %ptrs)
ret <4 x i32> %res
}
; CHECK: define i32 @volatile_load(
; CHECK-NOT: readonly
; CHECK: ret
define i32 @volatile_load(i32* %p) {
%load = load volatile i32, i32* %p
ret i32 %load
}