diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 6 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/no_sink_instruction.ll | 19 |
2 files changed, 24 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 34a5e1955b6..8506cf9baee 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -120,6 +120,10 @@ DEBUG_COUNTER(VisitCounter, "instcombine-visit", "Controls which instructions are visited"); static cl::opt<bool> +EnableCodeSinking("instcombine-code-sinking", cl::desc("Enable code sinking"), + cl::init(true)); + +static cl::opt<bool> EnableExpensiveCombines("expensive-combines", cl::desc("Enable expensive instruction combines")); @@ -3103,7 +3107,7 @@ bool InstCombiner::run() { } // See if we can trivially sink this instruction to a successor basic block. - if (I->hasOneUse()) { + if (EnableCodeSinking && I->hasOneUse()) { BasicBlock *BB = I->getParent(); Instruction *UserInst = cast<Instruction>(*I->user_begin()); BasicBlock *UserParent; diff --git a/llvm/test/Transforms/InstCombine/no_sink_instruction.ll b/llvm/test/Transforms/InstCombine/no_sink_instruction.ll new file mode 100644 index 00000000000..caeba16fa2e --- /dev/null +++ b/llvm/test/Transforms/InstCombine/no_sink_instruction.ll @@ -0,0 +1,19 @@ +; RUN: opt -instcombine -instcombine-code-sinking=0 -S < %s | FileCheck %s + +define i32 @test(i1 %C, i32 %A, i32 %B) { +; CHECK-LABEL: @test( +; CHECK: sdiv i32 +; CHECK-NEXT: add i32 +entry: + %tmp.2 = sdiv i32 %A, %B ; <i32> [#uses=1] + %tmp.9 = add i32 %B, %A ; <i32> [#uses=1] + br i1 %C, label %then, label %endif + +then: ; preds = %entry +; CHECK: ret i32 + ret i32 %tmp.9 + +endif: ; preds = %entry +; CHECK: ret i32 + ret i32 %tmp.2 +} |