Skip to content

Commit 5e5af53

Browse files
author
Yevgeny Rouban
committedOct 21, 2019
[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 llvm-svn: 375389
1 parent ee88119 commit 5e5af53

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
 

‎llvm/lib/IR/Instruction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ bool Instruction::mayReadFromMemory() const {
524524
case Instruction::Call:
525525
case Instruction::Invoke:
526526
case Instruction::CallBr:
527-
return !cast<CallBase>(this)->doesNotAccessMemory();
527+
return !cast<CallBase>(this)->doesNotReadMemory();
528528
case Instruction::Store:
529529
return !cast<StoreInst>(this)->isUnordered();
530530
}

‎llvm/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.init.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ define amdgpu_kernel void @gws_init_vgpr_offset_add(i32 %val) #0 {
114114
; LOOP: s_mov_b32 m0, -1
115115
; LOOP: ds_write_b32
116116
define amdgpu_kernel void @gws_init_save_m0_init_constant_offset(i32 %val) #0 {
117-
store i32 1, i32 addrspace(3)* @lds
117+
store volatile i32 1, i32 addrspace(3)* @lds
118118
call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 10)
119119
store i32 2, i32 addrspace(3)* @lds
120120
ret void
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: opt -S -early-cse < %s | FileCheck %s
2+
3+
@var = global i32 undef
4+
declare void @foo() nounwind
5+
6+
define void @test() {
7+
; CHECK-LABEL: @test(
8+
; CHECK-NOT: store
9+
store i32 1, i32* @var
10+
; CHECK: call void @foo()
11+
call void @foo() writeonly
12+
; CHECK: store i32 2, i32* @var
13+
store i32 2, i32* @var
14+
ret void
15+
}

0 commit comments

Comments
 (0)