[llvm] [InstCombine] Fold selection between less than zero and one (PR #69961)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 20:08:39 PDT 2023
XChy 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);
> }
> ```
m_Cmp -> m_ICmp
m_ConstantInt -> m_SpecificInt(getScalarSizeInBits() - 1)
m_APInt(C3) -> m_One()
Builder.CreateICmpSLE -> Builder.CreateICmpSLT
RArm -> C3
You may need to refer to https://reviews.llvm.org/D154791 and https://github.com/llvm/llvm-project/pull/68244.
https://github.com/llvm/llvm-project/pull/69961
More information about the llvm-commits
mailing list