https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77499
--- Comment #31 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For the non constant case and we know both are HImode originally.
We currently expand it like:
(insn 34 33 35 5 (set (reg:SI 122)
(xor:SI (reg/v:SI 106 [ tt ])
(reg/v:SI 102 [ x ]))) "/app/example.cpp":10:5 -1
(nil))
(insn 35 34 36 5 (set (reg/v:SI 102 [ x ])
(zero_extend:SI (subreg:HI (reg:SI 122) 0))) "/app/example.cpp":10:5 -1
(nil))
But we should just expand it as:
(insn 34 33 35 5 (set (reg/v:SI 102 [ x ])
(xor:SI (reg/v:SI 106 [ tt ])
(reg/v:SI 102 [ x ]))) "/app/example.cpp":10:5 -1
(nil))
Since we know both tt and x are already zero extended.
Note since GCC 15, we do remove a zero_extend from the front but that is way
after expansion and having it at the top of the function is better than having
a zero_extend each iteration in the loop.