https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120372
Bug ID: 120372
Summary: canonicalize_comparison uses gen_move_insn to
calcualate the cost of the constant formation
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: middle-end
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
Take:
```
int check1 (int x)
{
return x > 0xaa9fff;
}
```
Currently canonicalize_comparison gives:
;; cmp: gt, old cst: (const_int 11182079 [0xaa9fff]) new cst: (const_int
11182080 [0xaaa000])
;; old cst cost: 8, new cst cost: 8
Which is correct if we are forming a constant by itself. But the cmp
instruction can take a different constant than if we are just forming the
constant.
Note the middle-end also checks:
rtx_cost (x, mode, COMPARE, 0, optimize_insn_for_speed_p ())
In a different code. So maybe canonicalize_comparison should use that instead.