[llvm] [InstCombine] Fix pointer replacement in `foldSelectValueEquivalence` (PR #161701)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 2 11:57:15 PDT 2025
antoniofrighetto wrote:
> > > > Maybe I'm missing something, but at least from the tests, aren't the three canReplacePointersIfEqual being invoked on the same pointers all the times? Couldn't this be done only once?
> > >
> > >
> > > It is not commutative. You can always replace a pointer with a known dereferencable one.
> >
> >
> > Sorry, I'm not clear. I do understand isDereferenceablePointer is called on different pointers, though, now, canReplacePointersIfEqual(CmpLHS, CmpRHS) is being called twice (one in ReplaceOldOpWithNewOp, one later), and so is canReplacePointersIfEqual(CmpRHS, CmpLHS). Why cannot this be done once for both the operands?
>
> I will cache the result.
Thanks. BTW, what I had in mind originally was something along the following lines:
```cpp
bool RP1 = canReplacePointersIfEqual(CmpLHS, CmpRHS, DL);
if (Instruction *R = ReplaceOldOpWithNewOp(CmpLHS, CmpRHS, RP1))
return R;
bool RP2 = canReplacePointersIfEqual(CmpRHS, CmpLHS, DL);
if (Instruction *R = ReplaceOldOpWithNewOp(CmpRHS, CmpLHS, RP2))
return R;
```
And later `if ((RP1 && simplifyWithOpReplaced()) || (RP2 && simplifyWithOpReplaced())`.
https://github.com/llvm/llvm-project/pull/161701
More information about the llvm-commits
mailing list