[PATCH] D36975: [InstCombine] Fold branches with irrelevant conditions to a constant
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 23 02:17:50 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311540: [InstCombine] Fold branches with irrelevant conditions to a constant. (authored by davide).
Changed prior to commit:
https://reviews.llvm.org/D36975?vs=112143&id=112315#toc
Repository:
rL LLVM
https://reviews.llvm.org/D36975
Files:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/branch.ll
llvm/trunk/test/Transforms/InstCombine/pr33765.ll
llvm/trunk/test/Transforms/InstCombine/select-cmp-br.ll
Index: llvm/trunk/test/Transforms/InstCombine/pr33765.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/pr33765.ll
+++ llvm/trunk/test/Transforms/InstCombine/pr33765.ll
@@ -6,7 +6,7 @@
define void @patatino(i8 %beth) {
; CHECK-LABEL: @patatino(
; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[BETH:%.*]] to i32
-; CHECK-NEXT: br i1 undef, label [[IF_THEN9:%.*]], label [[IF_THEN9]]
+; CHECK-NEXT: br i1 false, label [[IF_THEN9:%.*]], label [[IF_THEN9]]
; CHECK: if.then9:
; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[CONV]], [[CONV]]
; CHECK-NEXT: [[TINKY:%.*]] = load i16, i16* @glob, align 2
Index: llvm/trunk/test/Transforms/InstCombine/select-cmp-br.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/select-cmp-br.ll
+++ llvm/trunk/test/Transforms/InstCombine/select-cmp-br.ll
@@ -248,7 +248,7 @@
define i32 @test6(i32 %arg, i1 %arg1) {
; CHECK-LABEL: @test6(
; CHECK-NEXT: entry:
-; CHECK-NEXT: br i1 undef, label [[BB:%.*]], label [[BB]]
+; CHECK-NEXT: br i1 false, label [[BB:%.*]], label [[BB]]
; CHECK: bb:
; CHECK-NEXT: [[TMP:%.*]] = select i1 [[ARG1:%.*]], i32 [[ARG:%.*]], i32 0
; CHECK-NEXT: ret i32 [[TMP]]
Index: llvm/trunk/test/Transforms/InstCombine/branch.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/branch.ll
+++ llvm/trunk/test/Transforms/InstCombine/branch.ll
@@ -1,16 +1,27 @@
+; Check that we fold the condition of branches of the
+; form: br <condition> dest1, dest2, where dest1 == dest2.
; RUN: opt -instcombine -S < %s | FileCheck %s
define i32 @test(i32 %x) {
; CHECK-LABEL: @test
entry:
; CHECK-NOT: icmp
-; CHECK: br i1 undef,
+; CHECK: br i1 false
%cmp = icmp ult i32 %x, 7
br i1 %cmp, label %merge, label %merge
merge:
; CHECK-LABEL: merge:
; CHECK: ret i32 %x
ret i32 %x
}
+ at global = global i8 0
+define i32 @pat(i32 %x) {
+; CHECK-NOT: icmp false
+; CHECK: br i1 false
+ %y = icmp eq i32 27, ptrtoint(i8* @global to i32)
+ br i1 %y, label %patatino, label %patatino
+patatino:
+ ret i32 %x
+}
Index: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2260,10 +2260,9 @@
// 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()));
+ if (BI.isConditional() && !isa<ConstantInt>(BI.getCondition()) &&
+ BI.getSuccessor(0) == BI.getSuccessor(1)) {
+ BI.setCondition(ConstantInt::getFalse(BI.getCondition()->getType()));
return &BI;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36975.112315.patch
Type: text/x-patch
Size: 3032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170823/5d565de5/attachment.bin>
More information about the llvm-commits
mailing list