[llvm] r345248 - Add -instcombine-code-sinking option

Gabor Buella via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 25 01:32:29 PDT 2018


Author: gbuella
Date: Thu Oct 25 01:32:29 2018
New Revision: 345248

URL: http://llvm.org/viewvc/llvm-project?rev=345248&view=rev
Log:
Add -instcombine-code-sinking option

Reviewers: craig.topper, andrew.w.kaylor, efriedma

Reviewed By: craig.topper, andrew.w.kaylor, efriedma

Differential Revision: https://reviews.llvm.org/D52709

Added:
    llvm/trunk/test/Transforms/InstCombine/no_sink_instruction.ll
Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=345248&r1=345247&r2=345248&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Thu Oct 25 01:32:29 2018
@@ -120,6 +120,10 @@ DEBUG_COUNTER(VisitCounter, "instcombine
               "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;

Added: llvm/trunk/test/Transforms/InstCombine/no_sink_instruction.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/no_sink_instruction.ll?rev=345248&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/no_sink_instruction.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/no_sink_instruction.ll Thu Oct 25 01:32:29 2018
@@ -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
+}




More information about the llvm-commits mailing list