[llvm] r272495 - [MergedLoadStoreMotion] Use correct helper for load hoist safety.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 11 19:11:20 PDT 2016
Author: efriedma
Date: Sat Jun 11 21:11:20 2016
New Revision: 272495
URL: http://llvm.org/viewvc/llvm-project?rev=272495&view=rev
Log:
[MergedLoadStoreMotion] Use correct helper for load hoist safety.
It isn't legal to hoist a load past a call which might not return;
even if it doesn't throw, it could, for example, call exit().
Fixes http://llvm.org/PR27953.
Modified:
llvm/trunk/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
llvm/trunk/test/Transforms/InstMerge/exceptions.ll
Modified: llvm/trunk/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp?rev=272495&r1=272494&r2=272495&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp Sat Jun 11 21:11:20 2016
@@ -79,6 +79,7 @@
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
+#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/Debug.h"
@@ -232,7 +233,7 @@ bool MergedLoadStoreMotion::isLoadHoistB
if (!SafeToLoadUnconditionally)
for (const Instruction &Inst :
make_range(Start.getIterator(), End.getIterator()))
- if (Inst.mayThrow())
+ if (!isGuaranteedToTransferExecutionToSuccessor(&Inst))
return true;
MemoryLocation Loc = MemoryLocation::get(LI);
return AA->canInstructionRangeModRef(Start, End, Loc, MRI_Mod);
Modified: llvm/trunk/test/Transforms/InstMerge/exceptions.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstMerge/exceptions.ll?rev=272495&r1=272494&r2=272495&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstMerge/exceptions.ll (original)
+++ llvm/trunk/test/Transforms/InstMerge/exceptions.ll Sat Jun 11 21:11:20 2016
@@ -11,12 +11,12 @@ entry:
br i1 %cmp, label %if.then, label %if.else
if.then: ; preds = %entry
- call void @may_throw()
+ call void @may_exit() nounwind
%arrayidx = getelementptr inbounds i32, i32* %p, i64 1
%0 = load i32, i32* %arrayidx, align 4
store i32 %0, i32* @r, align 4
br label %if.end
-; CHECK: call void @may_throw()
+; CHECK: call void @may_exit()
; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i32, i32* %p, i64 1
; CHECK-NEXT: %[[load:.*]] = load i32, i32* %[[gep]], align 4
; CHECK-NEXT: store i32 %[[load]], i32* @r, align 4
@@ -55,3 +55,4 @@ if.end:
}
declare void @may_throw()
+declare void @may_exit() nounwind
More information about the llvm-commits
mailing list