[llvm] [InstCombine] Fold selection between less than zero and one (PR #69961)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 19:16:47 PDT 2023


================
@@ -3415,6 +3415,20 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
                                 TrueVal);
   }
 
+  // select (icmp eq a, 0), 1, (lshr a, 31) -> icmp sle a, 0,
+  // which is then converted to icmp sle a, 1
+  CmpInst::Predicate Pred;
+  Value *A;
+  const APInt *C;
+  if (match(CondVal, m_Cmp(Pred, m_Value(A), m_Zero())) &&
+      match(TrueVal, m_One()) &&
+      match(FalseVal, m_LShr(m_Specific(A), m_APInt(C))) &&
+      Pred == ICmpInst::ICMP_EQ && *C == 31) {
----------------
arsenm wrote:

Hardcoded assumption of i32 instead of bit width - 1?

https://github.com/llvm/llvm-project/pull/69961


More information about the llvm-commits mailing list