https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104914
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|target |rtl-optimization
Ever confirmed|0 |1
Last reconfirmed| |2023-07-06
Status|UNCONFIRMED |NEW
Known to fail| |11.2.0
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The initial RTL has a signed extend in there:
(insn 20 19 23 2 (set (reg/v:DI 200 [ val+-4 ])
(sign_extend:DI (subreg:SI (reg/v:DI 200 [ val+-4 ]) 4)))
"/app/example.cpp":7:29 -1
(nil))
(jump_insn 23 20 24 2 (set (pc)
(if_then_else (le (subreg/s/u:SI (reg/v:DI 200 [ val+-4 ]) 4)
(const_int 0 [0]))
(label_ref 32)
(pc))) "/app/example.cpp":8:5 -1
(int_list:REG_BR_PROB 440234148 (nil))
-> 32)
Before combine also looks fine:
(insn 20 19 23 2 (set (reg/v:DI 200 [ val+-4 ])
(sign_extend:DI (subreg:SI (reg/v:DI 200 [ val+-4 ]) 4)))
"/app/example.cpp":7:29 235 {extendsidi2}
(nil))
(jump_insn 23 20 24 2 (set (pc)
(if_then_else (le (subreg/s/u:SI (reg/v:DI 200 [ val+-4 ]) 4)
(const_int 0 [0]))
(label_ref 32)
(pc))) "/app/example.cpp":8:5 471 {*branch_ordersi}
(expr_list:REG_DEAD (reg/v:DI 200 [ val+-4 ])
(int_list:REG_BR_PROB 440234148 (nil)))
-> 32)
But combine does the wrong thing:
Trying 20 -> 23:
20: r200:DI=sign_extend(r200:DI#4)
23: pc={(r200:DI#4<=0)?L32:pc}
REG_DEAD r200:DI
REG_BR_PROB 440234148
Successfully matched this instruction:
(set (pc)
(if_then_else (le (subreg:SI (reg/v:DI 200 [ valD.1959+-4 ]) 4)
(const_int 0 [0]))
(label_ref 32)
(pc)))
allowing combination of insns 20 and 23
original costs 4 + 16 = 20
replacement cost 16
deferring deletion of insn with uid = 20.
modifying insn i3 23: pc={(r200:DI#4<=0)?L32:pc}
REG_BR_PROB 440234148
REG_DEAD r200:DI
deferring rescan insn with uid = 23.
Instead of a subreg here, it should have been a truncate.