[llvm] r231881 - If a conditional branch jumps to the same target, remove the condition
Philip Reames
listmail at philipreames.com
Tue Mar 10 15:52:37 PDT 2015
Author: reames
Date: Tue Mar 10 17:52:37 2015
New Revision: 231881
URL: http://llvm.org/viewvc/llvm-project?rev=231881&view=rev
Log:
If a conditional branch jumps to the same target, remove the condition
Given that large parts of inst combine is restricted to instructions which have one use, getting rid of a use on the condition can help the effectiveness of the optimizer. Also, it allows the condition to potentially be deleted by instcombine rather than waiting for another pass.
I noticed this completely by accident in another test case. It's not anything that actually came from a real workload.
p.s. We should probably do the same thing for switch instructions.
Differential Revision: http://reviews.llvm.org/D8220
Added:
llvm/trunk/test/Transforms/InstCombine/branch.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=231881&r1=231880&r2=231881&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Tue Mar 10 17:52:37 2015
@@ -2002,6 +2002,15 @@ Instruction *InstCombiner::visitBranchIn
return &BI;
}
+ // If the condition is irrelevant, remove the use so that other
+ // transforms on the condition become more effective.
+ if (BI.isConditional() &&
+ BI.getSuccessor(0) == BI.getSuccessor(1) &&
+ !isa<UndefValue>(BI.getCondition())) {
+ BI.setCondition(UndefValue::get(BI.getCondition()->getType()));
+ return &BI;
+ }
+
// Canonicalize fcmp_one -> fcmp_oeq
FCmpInst::Predicate FPred; Value *Y;
if (match(&BI, m_Br(m_FCmp(FPred, m_Value(X), m_Value(Y)),
Added: llvm/trunk/test/Transforms/InstCombine/branch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/branch.ll?rev=231881&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/branch.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/branch.ll Tue Mar 10 17:52:37 2015
@@ -0,0 +1,16 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+define i32 @test(i32 %x) {
+; CHECK-LABEL: @test
+entry:
+; CHECK-NOT: icmp
+; CHECK: br i1 undef,
+ %cmp = icmp ult i32 %x, 7
+ br i1 %cmp, label %merge, label %merge
+merge:
+; CHECK-LABEL: merge:
+; CHECK: ret i32 %x
+ ret i32 %x
+}
+
+
More information about the llvm-commits
mailing list