Skip to content

Commit efe6a84

Browse files
author
Fiona Glaser
committed
[Sink] Really really fix predicate in legality check
LoadInst isn't enough; we need to include intrinsics that perform loads too. All side-effecting intrinsics and such are already covered by the isSafe check, so we just need to care about things that read from memory. D41960, originally from D33179. llvm-svn: 322311
1 parent 1ee1f49 commit efe6a84

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

llvm/lib/Transforms/Scalar/Sink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static bool IsAcceptableTarget(Instruction *Inst, BasicBlock *SuccToSinkTo,
114114
if (SuccToSinkTo->getUniquePredecessor() != Inst->getParent()) {
115115
// We cannot sink a load across a critical edge - there may be stores in
116116
// other code paths.
117-
if (isa<LoadInst>(Inst))
117+
if (Inst->mayReadFromMemory())
118118
return false;
119119

120120
// We don't want to sink across a critical edge if we don't dominate the
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
; RUN: opt < %s -basicaa -sink -S | FileCheck %s
22
declare void @foo(i64 *)
3-
define i64 @sinkload(i1 %cmp) {
3+
declare i8* @llvm.load.relative.i32(i8* %ptr, i32 %offset) argmemonly nounwind readonly
4+
define i64 @sinkload(i1 %cmp, i8* %ptr, i32 %off) {
45
; CHECK-LABEL: @sinkload
56
top:
67
%a = alloca i64
78
; CHECK: call void @foo(i64* %a)
89
; CHECK-NEXT: %x = load i64, i64* %a
10+
; CHECK-NEXT: %y = call i8* @llvm.load.relative.i32(i8* %ptr, i32 %off)
911
call void @foo(i64* %a)
1012
%x = load i64, i64* %a
13+
%y = call i8* @llvm.load.relative.i32(i8* %ptr, i32 %off)
1114
br i1 %cmp, label %A, label %B
1215
A:
1316
store i64 0, i64 *%a
17+
store i8 0, i8 *%ptr
1418
br label %B
1519
B:
1620
; CHECK-NOT: load i64, i64 *%a
17-
ret i64 %x
21+
; CHECK-NOT: call i8* @llvm.load.relative(i8* %ptr, i32 off)
22+
%y2 = ptrtoint i8* %y to i64
23+
%retval = add i64 %y2, %x
24+
ret i64 %retval
1825
}
26+

0 commit comments

Comments
 (0)