]> granicus.if.org Git - llvm/commitdiff
[IR] Fix mayReadFromMemory() for writeonly calls
authorYevgeny Rouban <yevgeny.rouban@azul.com>
Mon, 21 Oct 2019 06:52:08 +0000 (06:52 +0000)
committerYevgeny Rouban <yevgeny.rouban@azul.com>
Mon, 21 Oct 2019 06:52:08 +0000 (06:52 +0000)
Current implementation of Instruction::mayReadFromMemory()
returns !doesNotAccessMemory() which is !ReadNone. This
does not take into account that the writeonly attribute
also indicates that the call does not read from memory.

The patch changes the predicate to !doesNotReadMemory()
that reflects the intended behavior.

Differential Revision: https://reviews.llvm.org/D69086

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375389 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Instruction.cpp
test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.init.ll
test/Transforms/EarlyCSE/writeonly.ll [new file with mode: 0644]

index ba5629d1662bbd69455095587393f292de0b842c..b157c7bb34bfaf01106a20346a1ddc4868b50684 100644 (file)
@@ -524,7 +524,7 @@ bool Instruction::mayReadFromMemory() const {
   case Instruction::Call:
   case Instruction::Invoke:
   case Instruction::CallBr:
-    return !cast<CallBase>(this)->doesNotAccessMemory();
+    return !cast<CallBase>(this)->doesNotReadMemory();
   case Instruction::Store:
     return !cast<StoreInst>(this)->isUnordered();
   }
index a7a8fa7f2ccfcc958e2c5890c6ed42e13c1e3a58..9c39593d90379db99c4e84561cf65596197e5868 100644 (file)
@@ -114,7 +114,7 @@ define amdgpu_kernel void @gws_init_vgpr_offset_add(i32 %val) #0 {
 ; LOOP: s_mov_b32 m0, -1
 ; LOOP: ds_write_b32
 define amdgpu_kernel void @gws_init_save_m0_init_constant_offset(i32 %val) #0 {
-  store i32 1, i32 addrspace(3)* @lds
+  store volatile i32 1, i32 addrspace(3)* @lds
   call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 10)
   store i32 2, i32 addrspace(3)* @lds
   ret void
diff --git a/test/Transforms/EarlyCSE/writeonly.ll b/test/Transforms/EarlyCSE/writeonly.ll
new file mode 100644 (file)
index 0000000..0a3cd1c
--- /dev/null
@@ -0,0 +1,15 @@
+; RUN: opt -S -early-cse < %s | FileCheck %s
+
+@var = global i32 undef
+declare void @foo() nounwind
+
+define void @test() {
+; CHECK-LABEL: @test(
+; CHECK-NOT: store
+  store i32 1, i32* @var
+; CHECK: call void @foo()
+  call void @foo() writeonly
+; CHECK: store i32 2, i32* @var
+  store i32 2, i32* @var
+  ret void
+}