On Tue, Jun 30, 2026 at 7:31 AM Jeffrey Law <[email protected]> wrote: > > > > On 6/30/2026 4:59 AM, Richard Biener wrote: > > On Tue, Jun 30, 2026 at 10:52 AM Hongtao Liu <[email protected]> wrote: > >> To be conservative, perhaps I should first only handle the cases of 1 > >> and 2, so that a / (2 - bool) can be converted from a division into a > >> conditional shift, which should be profitable for all targets. > > Maybe. I still wouldn't do this from GIMPLE. > The 1/2 case would likely be non-controversial for the expansion step > given its a conditional right shift which has easily synthesizable forms.
I was going to say even the `[1,1][pow2,pow2]` range (with non-negative values) should be non-controversial as a/1 is just a. So you are left with `a/pow2` while before you had `a/value`. and that `a/pow2` would be a shift (well non controversial when shifts are cheap that is; there are targets [avr] where it might be worse because it only shifts one at a time; so /2 would be ok there). I have not looked into the code to see if it detects the 2 value range or a range that has sequenced values though. Thanks, Andrew > > The other cases are a bit more borderline, though we could at least > query costs in the gimple->RTL expansion phase to help guide the decisions. > > Jeff
