https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123020
--- Comment #7 from Castle "SkyWave" Sun <skywave2023 at outlook dot com> ---
(In reply to Andrew Pinski from comment #4)
> Confirmed.
>
> for aarch64 we have
> ```
> (insn 14 13 15 3 (set (reg/v:SI 106 [ mx ])
> (reg/v:SI 103 [ mx ])) 103 {*movsi_aarch64}
> (nil))
> (insn 15 14 16 3 (set (reg:CC 66 cc)
> (compare:CC (reg/v:SI 103 [ mx ])
> (reg:SI 108 [ _25 ]))) "/app/example.cpp":40:20 451 {cmpsi}
> (nil))
> (insn 16 15 17 3 (set (reg/v:SI 103 [ mx ])
> (if_then_else:SI (geu (reg:CC 66 cc)
> (const_int 0 [0]))
> (reg/v:SI 103 [ mx ])
> (reg:SI 108 [ _25 ]))) "/app/example.cpp":40:20 503
> {*cmovsi_insn}
> (expr_list:REG_DEAD (reg:CC 66 cc)
> (nil)))
> (insn 17 16 53 3 (set (reg:CC 66 cc)
> (compare:CC (reg/v:SI 106 [ mx ])
> (reg:SI 108 [ _25 ]))) "/app/example.cpp":41:21 451 {cmpsi}
> (expr_list:REG_DEAD (reg/v:SI 106 [ mx ])
> (nil)))
> ```
>
> But (reg:CC 66) is already set to the same thing and should have been
> removed But since we clobber 103 we don't notice it is the same.
>
>
> x86_64 is more complex:
> ```
> (insn 13 12 57 3 (parallel [
> (set (reg/v:SI 100 [ mx ])
> (umax:SI (reg/v:SI 100 [ mx ])
> (reg:SI 105 [ _25 ])))
> (clobber (reg:CC 17 flags))
> ]) "/app/example.cpp":40:20 1883 {*umaxsi3_1}
> (expr_list:REG_UNUSED (reg:CC 17 flags)
> (nil)))
> (insn 57 13 59 3 (set (reg:DI 110 [ _27 ])
> (zero_extend:DI (reg:SI 105 [ _25 ]))) "/app/example.cpp":41:13
> discrim 3 179 {*zero_extendsidi2}
> (nil))
> (insn 59 57 60 3 (parallel [
> (set (reg:DI 125)
> (plus:DI (reg/v:DI 104 [ sum ])
> (reg:DI 110 [ _27 ])))
> (clobber (reg:CC 17 flags))
> ]) "/app/example.cpp":41:13 discrim 3 289 {*adddi_1}
> (expr_list:REG_DEAD (reg:DI 110 [ _27 ])
> (expr_list:REG_UNUSED (reg:CC 17 flags)
> (nil))))
> (insn 60 59 61 3 (set (reg:CC 17 flags)
> (compare:CC (reg/v:SI 103 [ mx ])
> (reg:SI 105 [ _25 ]))) "/app/example.cpp":41:13 discrim 3 15
> {*cmpsi_1}
> (expr_list:REG_DEAD (reg:SI 105 [ _25 ])
> (expr_list:REG_DEAD (reg/v:SI 103 [ mx ])
> (nil))))
> ```
>
>
> For the gimple level. The problem is we convert `flag ? a[i] : mx;` into
> MAX_EXPR but I had assumed ethread would have done the jump thread
> beforehand ...
Thanks for the detailed analysis and the pointers!
Please let me know if I can help by testing a patch once there is one.