https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128770
--- Comment #1 from Hongyu Wang <hongyuw at gcc dot gnu.org> ---
Some more detail on why COMISS and VCOMXSS end up on different ifcvt paths,
and a correction to the description above: ix86_expand_fp_movcc is never
called for the VCOMX case.
The only difference at expand time is the flags setter:
COMISS: (set (reg:CCFP flags) (compare:CCFP a b))
VCOMXSS: (set (reg:CCFP flags)
(unspec:CCFP [(compare:CCFP a b)] UNSPEC_OPTCOMX))
The jump is (ne (reg:CCFP flags) 0) in both cases. In ce1,
noce_get_condition -> canonicalize_condition walks back from the jump to the
flags setter and substitutes its operands only if SET_SRC is a COMPARE (or a
cmp_code/xor). For an unspec it breaks early, so the canonicalization returns:
COMISS: cond = (ne a b), cond_earliest = the COMISS insn
VCOMXSS: cond = (ne flags 0), cond_earliest = the jump
noce_try_cmove -> noce_emit_cmove then behaves differently:
- COMISS: cond_earliest != jump, so the "build the cmove insn directly" step
is skipped and emit_conditional_move goes to the movsfcc expander.
ix86_expand_fp_movcc sees an SFmode compare and emits
vcmpneqss + vblendvps. COMISS is left dead and DCE removes it in ce1.
- VCOMXSS: cond_earliest == jump, so noce_emit_cmove first tries to recog
(set x (if_then_else (ne (reg:CCFP flags) 0) c d)) directly. This matches
*movsfcc_1_387, so the expander is never run. After reload the sequence
become is vmovd + vmovd + cmovne + vmovd. In the loop case the same GPR
sequence costs more than the branch, so the branch stays.
The USPEC_NOTRAP series meets similar issue. So this raises another topic that
how we should better describing the compare sematics, or whether we need to
adjust the pattern or expander (like, gating movsfcc_1_387 under no_sse_math).
But for this bugzila, the standalone HONOR_NAN gate for vcomx is still valid,
as under -ffinite-math-only COMISS sets ZF correctly and no need for comx.