[PATCH] D148413: [InstCombine] Remove requirement on `trunc` in `slt/sgt` case in `foldSelectICmpAndOr`

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 23:12:10 PDT 2023


goldstein.w.n created this revision.
goldstein.w.n added reviewers: majnemer, spatel, nikic, craig.topper.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

AFAICT, the trunc is not needed for correctness/performance and just
blocks what should be handlable cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148413

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll


Index: llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll
===================================================================
--- llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll
+++ llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll
@@ -760,9 +760,9 @@
 
 define i8 @test70(i8 %x, i8 %y) {
 ; CHECK-LABEL: @test70(
-; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
-; CHECK-NEXT:    [[OR:%.*]] = or i8 [[Y:%.*]], 2
-; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[CMP]], i8 [[OR]], i8 [[Y]]
+; CHECK-NEXT:    [[TMP1:%.*]] = lshr i8 [[X:%.*]], 6
+; CHECK-NEXT:    [[TMP2:%.*]] = and i8 [[TMP1]], 2
+; CHECK-NEXT:    [[SELECT:%.*]] = or i8 [[TMP2]], [[Y:%.*]]
 ; CHECK-NEXT:    ret i8 [[SELECT]]
 ;
   %cmp = icmp slt i8 %x, 0
Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -664,8 +664,7 @@
     C1Log = C1->logBase2();
     IsEqualZero = IC->getPredicate() == ICmpInst::ICMP_EQ;
   } else {
-    // We also need to recognize (icmp slt (trunc (X)), 0) and
-    // (icmp sgt (trunc (X)), -1).
+    // We also need to recognize (icmp slt X, 0) and (icmp sgt X, -1).
     if (IC->getPredicate() == ICmpInst::ICMP_SGT && match(CmpRHS, m_AllOnes()))
       IsEqualZero = true;
     if (IC->getPredicate() == ICmpInst::ICMP_SLT && match(CmpRHS, m_Zero()))
@@ -673,9 +672,6 @@
     else
       return nullptr;
 
-    if (!match(CmpLHS, m_OneUse(m_Trunc(m_Value(V)))))
-      return nullptr;
-
     C1Log = CmpLHS->getType()->getScalarSizeInBits() - 1;
     NeedAnd = true;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148413.513848.patch
Type: text/x-patch
Size: 1705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230415/d984c955/attachment.bin>


More information about the llvm-commits mailing list