[llvm] r259370 - [ValueTracking] Improve isKnownNonZero for PHI of non-zero constants
Jun Bum Lim via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 09:03:08 PST 2016
Author: junbuml
Date: Mon Feb 1 11:03:07 2016
New Revision: 259370
URL: http://llvm.org/viewvc/llvm-project?rev=259370&view=rev
Log:
[ValueTracking] Improve isKnownNonZero for PHI of non-zero constants
It is clear that a PHI is a non-zero if all incoming values are non-zero constants.
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/InstCombine/phi.ll
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=259370&r1=259369&r2=259370&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Feb 1 11:03:07 2016
@@ -2074,6 +2074,12 @@ bool isKnownNonZero(Value *V, unsigned D
}
}
}
+ // Check if all incoming values are non-zero constant.
+ bool AllNonZeroConstants = all_of(PN->operands(), [](Value *V) {
+ return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZeroValue();
+ });
+ if (AllNonZeroConstants)
+ return true;
}
if (!BitWidth) return false;
Modified: llvm/trunk/test/Transforms/InstCombine/phi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/phi.ll?rev=259370&r1=259369&r2=259370&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/phi.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/phi.ll Mon Feb 1 11:03:07 2016
@@ -760,3 +760,27 @@ epilog:
; CHECK-NEXT: ret i1 %[[RES]]
}
+; CHECK-LABEL: phi_allnonzeroconstant
+; CHECK-NOT: phi i32
+; CHECK: ret i1 false
+define i1 @phi_allnonzeroconstant(i1 %c, i32 %a, i32 %b) {
+entry:
+ br i1 %c, label %if.then, label %if.else
+
+if.then: ; preds = %entry
+ br label %if.end
+
+if.else: ; preds = %entry
+ call void @dummy()
+
+ br label %if.end
+
+if.end: ; preds = %if.else, %if.then
+ %x.0 = phi i32 [ 1, %if.then ], [ 2, %if.else ]
+ %or = or i32 %x.0, %a
+ %cmp1 = icmp eq i32 %or, 0
+ ret i1 %cmp1
+}
+
+declare void @dummy()
+
More information about the llvm-commits
mailing list