[llvm] r264996 - [InstCombine] Fix incorrect rule from rL236202
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 30 22:14:34 PDT 2016
Author: sanjoy
Date: Thu Mar 31 00:14:34 2016
New Revision: 264996
URL: http://llvm.org/viewvc/llvm-project?rev=264996&view=rev
Log:
[InstCombine] Fix incorrect rule from rL236202
The rule for SMIN introduced in rL236202 doesn't work as advertised: the
check for Pred == ICmpInst::ICMP_SGT was missing.
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/InstCombine/select.ll
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=264996&r1=264995&r2=264996&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Thu Mar 31 00:14:34 2016
@@ -3552,7 +3552,8 @@ static SelectPatternResult matchSelectPa
// Y >s C ? ~Y : ~C == ~Y <s ~C ? ~Y : ~C = SMIN(~Y, ~C)
if (const auto *C2 = dyn_cast<ConstantInt>(FalseVal)) {
- if (C1->getType() == C2->getType() && ~C1->getValue() == C2->getValue() &&
+ if (Pred == ICmpInst::ICMP_SGT && C1->getType() == C2->getType() &&
+ ~C1->getValue() == C2->getValue() &&
(match(TrueVal, m_Not(m_Specific(CmpLHS))) ||
match(CmpLHS, m_Not(m_Specific(TrueVal))))) {
LHS = TrueVal;
Modified: llvm/trunk/test/Transforms/InstCombine/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=264996&r1=264995&r2=264996&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/select.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/select.ll Thu Mar 31 00:14:34 2016
@@ -1589,3 +1589,21 @@ define i32 @PR23757(i32 %x) {
%sel = select i1 %cmp, i32 -2147483648, i32 %add
ret i32 %sel
}
+
+
+define i32 @PR27137(i32 %a) {
+; CHECK-LABEL: @PR27137(
+; CHECK-NEXT: %not_a = xor i32 %a, -1
+; CHECK-NEXT: %c0 = icmp slt i32 %a, 0
+; CHECK-NEXT: %s0 = select i1 %c0, i32 %not_a, i32 -1
+; CHECK-NEXT: %c1 = icmp sgt i32 %s0, -1
+; CHECK-NEXT: %s1 = select i1 %c1, i32 %s0, i32 -1
+; CHECK-NEXT: ret i32 %s1
+
+ %not_a = xor i32 %a, -1
+ %c0 = icmp slt i32 %a, 0
+ %s0 = select i1 %c0, i32 %not_a, i32 -1
+ %c1 = icmp sgt i32 %s0, -1
+ %s1 = select i1 %c1, i32 %s0, i32 -1
+ ret i32 %s1
+}
More information about the llvm-commits
mailing list