<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 13 May 2014 23:32, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi nicholas,<br>
<br>
We know that -(zext V) will always be <= zero, simplify signed icmps<br>
that have these.<br>
<br>
Uncovered using <a href="http://www.cs.utah.edu/~regehr/souper/" target="_blank">http://www.cs.utah.edu/~regehr/souper/</a><br>
<br>
<a href="http://reviews.llvm.org/D3754" target="_blank">http://reviews.llvm.org/D3754</a><br>
<br>
Files:<br>
lib/Analysis/InstructionSimplify.cpp<br>
test/Transforms/InstSimplify/compare.ll<br>
<br>
Index: lib/Analysis/InstructionSimplify.cpp<br>
===================================================================<br>
--- lib/Analysis/InstructionSimplify.cpp<br>
+++ lib/Analysis/InstructionSimplify.cpp<br>
@@ -2280,6 +2280,24 @@<br>
}<br>
}<br>
<br>
+ // 0 - (zext X) pred C<br>
+ if (match(LHS, m_Neg(m_ZExt(m_Value())))) {<br></blockquote><div><br></div><div>if (CmpInst::isSigned(Pred) && ICmpInst::isRelational(Pred) && match(...</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ if (ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {<br>
+ if (RHSC->getValue().isStrictlyPositive()) {<br>
+ if (Pred == ICmpInst::ICMP_SLT)<br>
+ return ConstantInt::getTrue(RHSC->getContext());<br>
+ if (Pred == ICmpInst::ICMP_SGE)<br>
+ return ConstantInt::getFalse(RHSC->getContext());<br>
+ }<br>
+ if (RHSC->getValue().isNonNegative()) {<br>
+ if (Pred == ICmpInst::ICMP_SLE)<br>
+ return ConstantInt::getTrue(RHSC->getContext());<br>
+ if (Pred == ICmpInst::ICMP_SGT)<br>
+ return ConstantInt::getFalse(RHSC->getContext());<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
// icmp pred (urem X, Y), Y<br>
if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) {<br>
bool KnownNonNegative, KnownNegative;<br>
Index: test/Transforms/InstSimplify/compare.ll<br>
===================================================================<br>
--- test/Transforms/InstSimplify/compare.ll<br>
+++ test/Transforms/InstSimplify/compare.ll<br>
@@ -757,3 +757,43 @@<br>
; CHECK-LABEL: @vectorselectfold<br>
; CHECK-NEXT: ret <4 x i8> %a<br>
}<br>
+<br>
+define i1 @compare_always_true_slt(i16 %a) {<br>
+ %1 = zext i16 %a to i32<br>
+ %2 = sub nsw i32 0, %1<br>
+ %3 = icmp slt i32 %2, 1<br>
+ ret i1 %3<br>
+<br>
+; CHECK-LABEL: @compare_always_true_slt<br>
+; CHECK-NEXT: ret i1 true<br>
+}<br>
+<br>
+define i1 @compare_always_true_sle(i16 %a) {<br>
+ %1 = zext i16 %a to i32<br>
+ %2 = sub nsw i32 0, %1<br>
+ %3 = icmp sle i32 %2, 0<br>
+ ret i1 %3<br>
+<br>
+; CHECK-LABEL: @compare_always_true_sle<br>
+; CHECK-NEXT: ret i1 true<br>
+}<br>
+<br>
+define i1 @compare_always_false_sgt(i16 %a) {<br>
+ %1 = zext i16 %a to i32<br>
+ %2 = sub nsw i32 0, %1<br>
+ %3 = icmp sgt i32 %2, 0<br>
+ ret i1 %3<br>
+<br>
+; CHECK-LABEL: @compare_always_false_sgt<br>
+; CHECK-NEXT: ret i1 false<br>
+}<br>
+<br>
+define i1 @compare_always_false_sge(i16 %a) {<br>
+ %1 = zext i16 %a to i32<br>
+ %2 = sub nsw i32 0, %1<br>
+ %3 = icmp sge i32 %2, 1<br>
+ ret i1 %3<br>
+<br>
+; CHECK-LABEL: @compare_always_false<br>
+; CHECK-NEXT: ret i1 false<br>
+}<br></blockquote><div><br></div><div>LGTM</div><div><br></div><div>Nick </div></div></div></div>