diff options
author | Hans Wennborg <hans@hanshq.net> | 2017-03-02 16:44:46 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2017-03-02 16:44:46 +0000 |
commit | 90a40679330e467b9836248b8619c33f261c9323 (patch) | |
tree | 64b4b9ad9bcc9fec6674bb2b0d25969c86a23f4f | |
parent | 7cdbbe055c72440cb05d3664bd07c1eee6cfaa5c (diff) | |
download | llvm-90a40679330e467b9836248b8619c33f261c9323.tar.gz |
Merging r296642:
------------------------------------------------------------------------
r296642 | hans | 2017-03-01 09:15:08 -0800 (Wed, 01 Mar 2017) | 5 lines
[GVNHoist] Don't hoist unsafe scalars at -Oz (PR31729)
Based on Aditya Kumar's patch:
Differential Revision: https://reviews.llvm.org/D29092
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@296761 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/GVNHoist.cpp | 31 | ||||
-rw-r--r-- | test/Transforms/GVNHoist/hoist-unsafe-pr31729.ll | 81 |
2 files changed, 90 insertions, 22 deletions
diff --git a/lib/Transforms/Scalar/GVNHoist.cpp b/lib/Transforms/Scalar/GVNHoist.cpp index 90c26e13db78..f8e1d2e1a08a 100644 --- a/lib/Transforms/Scalar/GVNHoist.cpp +++ b/lib/Transforms/Scalar/GVNHoist.cpp @@ -200,13 +200,11 @@ static void combineKnownMetadata(Instruction *ReplInst, Instruction *I) { class GVNHoist { public: GVNHoist(DominatorTree *DT, AliasAnalysis *AA, MemoryDependenceResults *MD, - MemorySSA *MSSA, bool OptForMinSize) - : DT(DT), AA(AA), MD(MD), MSSA(MSSA), OptForMinSize(OptForMinSize), - HoistingGeps(OptForMinSize), HoistedCtr(0) { - // Hoist as far as possible when optimizing for code-size. - if (OptForMinSize) - MaxNumberOfBBSInPath = -1; - } + MemorySSA *MSSA) + : DT(DT), AA(AA), MD(MD), MSSA(MSSA), + HoistingGeps(false), + HoistedCtr(0) + { } bool run(Function &F) { VN.setDomTree(DT); @@ -251,7 +249,6 @@ private: AliasAnalysis *AA; MemoryDependenceResults *MD; MemorySSA *MSSA; - const bool OptForMinSize; const bool HoistingGeps; DenseMap<const Value *, unsigned> DFSNumber; BBSideEffectsSet BBSideEffects; @@ -505,11 +502,6 @@ private: bool safeToHoistScalar(const BasicBlock *HoistBB, SmallPtrSetImpl<const BasicBlock *> &WL, int &NBBsOnAllPaths) { - // Enable scalar hoisting at -Oz as it is safe to hoist scalars to a place - // where they are partially needed. - if (OptForMinSize) - return true; - // Check that the hoisted expression is needed on all paths. if (!hoistingFromAllPaths(HoistBB, WL)) return false; @@ -923,13 +915,8 @@ private: Intr->getIntrinsicID() == Intrinsic::assume) continue; } - if (Call->mayHaveSideEffects()) { - if (!OptForMinSize) - break; - // We may continue hoisting across calls which write to memory. - if (Call->mayThrow()) - break; - } + if (Call->mayHaveSideEffects()) + break; if (Call->isConvergent()) break; @@ -971,7 +958,7 @@ public: auto &MD = getAnalysis<MemoryDependenceWrapperPass>().getMemDep(); auto &MSSA = getAnalysis<MemorySSAWrapperPass>().getMSSA(); - GVNHoist G(&DT, &AA, &MD, &MSSA, F.optForMinSize()); + GVNHoist G(&DT, &AA, &MD, &MSSA); return G.run(F); } @@ -991,7 +978,7 @@ PreservedAnalyses GVNHoistPass::run(Function &F, FunctionAnalysisManager &AM) { AliasAnalysis &AA = AM.getResult<AAManager>(F); MemoryDependenceResults &MD = AM.getResult<MemoryDependenceAnalysis>(F); MemorySSA &MSSA = AM.getResult<MemorySSAAnalysis>(F).getMSSA(); - GVNHoist G(&DT, &AA, &MD, &MSSA, F.optForMinSize()); + GVNHoist G(&DT, &AA, &MD, &MSSA); if (!G.run(F)) return PreservedAnalyses::all(); diff --git a/test/Transforms/GVNHoist/hoist-unsafe-pr31729.ll b/test/Transforms/GVNHoist/hoist-unsafe-pr31729.ll new file mode 100644 index 000000000000..654d5b6a5585 --- /dev/null +++ b/test/Transforms/GVNHoist/hoist-unsafe-pr31729.ll @@ -0,0 +1,81 @@ +; RUN: opt -gvn-hoist -S < %s | FileCheck %s + +; Check that urem is not hoisted. +; CHECK-LABEL: @main +; CHECK: urem +; CHECK: urem +; CHECK: urem + +@g_x_s = global i32 -470211272, align 4 +@g_z_s = global i32 2007237709, align 4 +@g_x_u = global i32 282475249, align 4 +@g_z_u = global i32 984943658, align 4 +@g_m = global i32 16807, align 4 +@res = common global i32 0, align 4 + +; Function Attrs: +define i64 @func() #0 { +entry: + ret i64 1 +} + +; Function Attrs: +define i32 @main() { +entry: + %0 = load volatile i32, i32* @g_x_s, align 4 + %1 = load volatile i32, i32* @g_z_s, align 4 + %2 = load volatile i32, i32* @g_x_u, align 4 + %3 = load volatile i32, i32* @g_z_u, align 4 + %4 = load volatile i32, i32* @g_m, align 4 + %call = call i64 @func() #4 + %conv = sext i32 %1 to i64 + %cmp = icmp ne i64 %call, %conv + br i1 %cmp, label %if.end, label %lor.lhs.false + +lor.lhs.false: + %div = udiv i32 %4, %1 + %rem = urem i32 %0, %div + %cmp2 = icmp eq i32 %rem, 0 + br i1 %cmp2, label %if.end, label %if.then + +if.then: + br label %cleanup + +if.end: + %call4 = call i64 @func() #4 + %conv5 = zext i32 %3 to i64 + %cmp6 = icmp ne i64 %call4, %conv5 + br i1 %cmp6, label %if.end14, label %lor.lhs.false8 + +lor.lhs.false8: + %div9 = udiv i32 %4, %3 + %rem10 = urem i32 %0, %div9 + %cmp11 = icmp eq i32 %rem10, 0 + br i1 %cmp11, label %if.end14, label %if.then13 + +if.then13: + br label %cleanup + +if.end14: + %call15 = call i64 @func() #4 + %cmp17 = icmp ne i64 %call15, %conv + br i1 %cmp17, label %if.end25, label %lor.lhs.false19 + +lor.lhs.false19: + %div20 = udiv i32 %4, %1 + %rem21 = urem i32 %0, %div20 + %cmp22 = icmp eq i32 %rem21, 0 + br i1 %cmp22, label %if.end25, label %if.then24 + +if.then24: + br label %cleanup + +if.end25: + br label %cleanup + +cleanup: + %retval.0 = phi i32 [ 0, %if.end25 ], [ 1, %if.then24 ], [ 1, %if.then13 ], [ 1, %if.then ] + ret i32 %retval.0 +} + +attributes #0 = { minsize noinline nounwind optsize uwtable "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" } |