[PATCH] D136582: [InstCombine] fold sub pattern to and

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 13:55:51 PDT 2022


spatel added a comment.

In D136582#3884899 <https://reviews.llvm.org/D136582#3884899>, @bcl5980 wrote:

> In D136582#3882587 <https://reviews.llvm.org/D136582#3882587>, @spatel wrote:
>
>> In D136582#3882497 <https://reviews.llvm.org/D136582#3882497>, @bcl5980 wrote:
>>
>>> In D136582#3882251 <https://reviews.llvm.org/D136582#3882251>, @spatel wrote:
>>>
>>>> In D136582#3880779 <https://reviews.llvm.org/D136582#3880779>, @bcl5980 wrote:
>>>>
>>>>> In D136582#3880098 <https://reviews.llvm.org/D136582#3880098>, @spatel wrote:
>>>>>
>>>>>> I don't know if it would have any effect on this patch, but we seem to be missing a constant-shrinking (DemandedBits) opportunity for sub nuw:
>>>>>> https://alive2.llvm.org/ce/z/7Lb_Dy
>>>>>>
>>>>>> We can clear high-bits of the mask constant based on the highest bit set in the subtract constant.
>>>>>
>>>>> Yeah, I also find the shrinking. And that part has no effect on this patch. Condition 1/3 don't care any high-bits for C2.
>>>>
>>>> This patch still seems too specific. 
>>>> Can we generalize this as a mask-of-subtract canonicalization instead - https://alive2.llvm.org/ce/z/qz_KmH ?
>>>> If we do that, an existing fold for subtract should reduce the motivating example.
>>>
>>> Thanks for the idea. It is a more clean and simplier way. 
>>> I only have a little concern about the subtract's combination after the canonicalization. For example:
>>> https://alive2.llvm.org/ce/z/i5Qk9-
>>> It will break exist `and` combination. Generally I think subtract's combination should be less than `and`.
>>
>> Good point. It seems we are missing some family of canonicalizations with subtract-from-constant and bitwise logic. There may be some common pre-condition with a low-bit mask and any logic op?
>> https://alive2.llvm.org/ce/z/qrsyWe
>
> The pattern is still complicate:
> https://alive2.llvm.org/ce/z/Mx5tNC

I think this can be reduced to low-bit mask constraints:
https://alive2.llvm.org/ce/z/dJqQHN
I also noticed a deficiency in demanded bits for sub. I don't know if that would cause trouble for this patch, but we probably want to do it to be consistent with `add`:
D136788 <https://reviews.llvm.org/D136788>


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136582/new/

https://reviews.llvm.org/D136582



More information about the llvm-commits mailing list