[llvm] r375389 - [IR] Fix mayReadFromMemory() for writeonly calls

Yevgeny Rouban via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 20 23:52:08 PDT 2019


Author: yrouban
Date: Sun Oct 20 23:52:08 2019
New Revision: 375389

URL: http://llvm.org/viewvc/llvm-project?rev=375389&view=rev
Log:
[IR] Fix mayReadFromMemory() for writeonly calls

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

Added:
    llvm/trunk/test/Transforms/EarlyCSE/writeonly.ll
Modified:
    llvm/trunk/lib/IR/Instruction.cpp
    llvm/trunk/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.init.ll

Modified: llvm/trunk/lib/IR/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instruction.cpp?rev=375389&r1=375388&r2=375389&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instruction.cpp (original)
+++ llvm/trunk/lib/IR/Instruction.cpp Sun Oct 20 23:52:08 2019
@@ -524,7 +524,7 @@ bool Instruction::mayReadFromMemory() co
   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();
   }

Modified: llvm/trunk/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.init.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.init.ll?rev=375389&r1=375388&r2=375389&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.init.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.init.ll Sun Oct 20 23:52:08 2019
@@ -114,7 +114,7 @@ define amdgpu_kernel void @gws_init_vgpr
 ; 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

Added: llvm/trunk/test/Transforms/EarlyCSE/writeonly.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/EarlyCSE/writeonly.ll?rev=375389&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/EarlyCSE/writeonly.ll (added)
+++ llvm/trunk/test/Transforms/EarlyCSE/writeonly.ll Sun Oct 20 23:52:08 2019
@@ -0,0 +1,15 @@
+; RUN: opt -S -early-cse < %s | FileCheck %s
+
+ at 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
+}




More information about the llvm-commits mailing list