[PATCH] D24844: GVN-hoist: disable hoisting stores past calls (PR30499)
Sebastian Pop via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 22 14:35:58 PDT 2016
sebpop created this revision.
sebpop added a reviewer: dberlin.
sebpop added a subscriber: llvm-commits.
MemoryLocation::get() does not support CallInst and it errors with llvm_unreachable("unsupported memory instruction");
The current patch avoids calling get() with CallInst.
https://reviews.llvm.org/D24844
Files:
llvm/lib/Transforms/Scalar/GVNHoist.cpp
llvm/test/Transforms/GVNHoist/pr30499.ll
Index: llvm/test/Transforms/GVNHoist/pr30499.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GVNHoist/pr30499.ll
@@ -0,0 +1,31 @@
+; RUN: opt -S -gvn-hoist < %s
+
+define void @_Z3fn2v() #0 {
+entry:
+ %a = alloca i8*, align 8
+ %b = alloca i32, align 4
+ %0 = load i8*, i8** %a, align 8
+ store i8 0, i8* %0, align 1
+ %1 = load i32, i32* %b, align 4
+ %tobool = icmp ne i32 %1, 0
+ br i1 %tobool, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %call = call i64 @_Z3fn1v() #2
+ %conv = trunc i64 %call to i32
+ store i32 %conv, i32* %b, align 4
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ %2 = load i8*, i8** %a, align 8
+ store i8 0, i8* %2, align 1
+ ret void
+}
+
+; Function Attrs: nounwind readonly
+declare i64 @_Z3fn1v() #1
+
+attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readonly }
+
Index: llvm/lib/Transforms/Scalar/GVNHoist.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -345,21 +345,27 @@
auto *MU = dyn_cast<MemoryUse>(&MA);
if (!MU)
continue;
+ Instruction *Insn = MU->getMemoryInst();
// Do not check whether MU aliases Def when MU occurs after OldPt.
- if (BB == OldBB && firstInBB(OldPt, MU->getMemoryInst()))
+ if (BB == OldBB && firstInBB(OldPt, Insn))
break;
// Do not check whether MU aliases Def when MU occurs before NewPt.
if (BB == NewBB) {
if (!ReachedNewPt) {
- if (firstInBB(MU->getMemoryInst(), NewPt))
+ if (firstInBB(Insn, NewPt))
continue;
ReachedNewPt = true;
}
}
- if (!AA->isNoAlias(DefLoc, MemoryLocation::get(MU->getMemoryInst())))
+ // Do not hoist stores past calls because MemoryLocation::get() does not
+ // work for CallInst.
+ if (isa<CallInst>(Insn))
+ return true;
+
+ if (!AA->isNoAlias(DefLoc, MemoryLocation::get(Insn)))
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24844.72213.patch
Type: text/x-patch
Size: 3062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160922/6cce577c/attachment.bin>
More information about the llvm-commits
mailing list