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

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 11:21:48 PDT 2023


elhewaty wrote:

@XChy What is wrong with this approach? 
```
CmpInst::Predicate Pred;
  Value *A;
  ConstantInt *C1, *C2;
  const APInt *C3;
  if (match(CondVal, m_Cmp(Pred, m_Value(A), m_ConstantInt(C1))) &&
      match(TrueVal, m_LShr(m_Specific(A), m_ConstantInt(C2))) &&
      match(FalseVal, m_APInt(C3)) && C3->isOne() &&
      C2->getValue() == C2->getValue().getBitWidth() - 1) {
    auto *Cond = Builder.CreateICmp(Pred, A, C1);
    auto *LArm = Builder.CreateICmpSLE(A, ConstantInt::getNullValue(A->getType()));
    Constant *RArm = ConstantInt::get(SelType, *C3);
    return SelectInst::Create(Cond, LArm, RArm);
  }
```

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


More information about the llvm-commits mailing list