[llvm] [InstCombine] Fix fail to fold (A >> C1) Pred C2 if shr is used multple times #83430 (PR #83563)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 04:35:27 PDT 2024
dtcxzyw wrote:
> @dtcxzyw, I was experimenting with SPF code and added some logic before the `if (TrueVal == CmpLHS && FalseVal == CmpRHS)` statement. but it didn't work because of this:
>
> ```llvm
> (lldb) expr SI->getCondition()->dump()
> %switch.i = xor i1 %cmp4.i, true
> ```
You should match this with `m_Not`, then update the cmp predicate with `CmpInst::getInversePredicate`.
```
bool Invert = false;
Value *Condition = SI->getCondition();
Value *X;
if (match(Condition, m_Not(X)) {
Invert = true;
Condition = X;
}
CmpInst::Predicate Pred;
Value *CmpLHS, *CmpRHS;
if (!match(Condition, m_ICmp(Pred, m_Value(CmpLHS), m_Value(CmpRHS)))
fail...
if (Invert)
Pred = CmpInst::getInversePredicate(Pred);
...
```
https://github.com/llvm/llvm-project/pull/83563
More information about the llvm-commits
mailing list