On 6/22/19 7:55 AM, Jason Duerstock wrote: > I was starting at the assembly from some of the Python source, and > came across this (simplified) comparison: > > if (x > 2305843009213693951) {...} > > This is the same as: > > if (x > 0x1fffffffffffffff) {...} > > This is equivalent to: > > if (x >> 61) {...} > > More generally, we can rewrite > > if ( x > ((1 << z) -1)) { ...} > > as > > if ( x >> z ) { ... } > > This does not appear to currently be a gcc optimization. What is > involved in adding it? So first, when discussing this kind of stuff it's usually best to actually have a compilable example. Fragments usually are insufficient.
Adding it to the RTL optimizers would be painful because of the need for type information (this is only valid when X is unsigned, right?) Adding it to the gimple optimizers is painful because the optimized form is actually de-optimized on some targets (say embedded targets with weak shifters) and querying the target costs/capabilities is generally frowned upon in the gimple optimizers. I think the combination of those two factors would tend to argue for an implementation in the gimple->rtl expanders. You've still got type information and you can query the backend for costing and capabilities. cfgexpand::expand_gimple_cond might be a good place to start. Another place to poke around would be expr:expand_expr_real_2, case COND_EXPR. Jeff