[llvm] [InstCombine] Fold `(X==Z || Y==Z) ? (X==Z && Y==Z) : X==Y --> X==Y` (PR #108619)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 09:26:07 PDT 2024


goldsteinn wrote:

> > It looks like InstCombine canonicalizes this to something like `(X == Z) ? (Y == Z) : !(Y == Z) && X == Y)`, see https://alive2.llvm.org/ce/z/XY_HMX. Shouldn't we be matching that pattern instead?
> 
> I am new in this area and unfamiliar with the conventions. My thought process was that matching something closer to the Swift-generated IR would better express the intent of this patch, and also I wasn't sure if I could rely on the altered form remaining stable over time. But if you think it would be better then I'm happy to update the patch.

Typically canonical patterns are what remain stable longer. They aren't folds that meaningful change the instructions, just standardize them in a way so that future matching code only needs to worry about a single iteration.
You can see more about it: https://llvm.org/docs/InstCombineContributorGuide.html#canonicalization-and-target-independence

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


More information about the llvm-commits mailing list