Attached patch cleans TEST insn patterns by removing unneeded alternatives from *testdi_1 (these were cargo-culted from *testsi_1, where they are used to describe pentium pairing, but pentium is not a 64bit target). The patch also removes manual definition of modrm attribute. This attribute is nowadays correctly calculated in a generic way for all "test" type insns also when AX register is used. Additionally, the patch changes test<mode>_ccno_1 insn name to a parametrized insn name and uses a generic gen_extend_insn infrastructure instead of calling named insn pattern directly.
2019-07-15 Uroš Bizjak <ubiz...@gmail.com> * config/i386/i386.md (@test<mode>_ccno_1): Rename from test<mode>_ccno_1. (*testdi_1): Remove redundant alternatives. Remove modrm attribute. (*testqi_1_maybe_si): Remove modrm attribute. (*test<mode>_1): Ditto. * config/i386/i386-expand.c (ix86_split_idivmod): Use gen_test_ccno_1 and gen_extend_insn. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline SVN. Uros.
Index: config/i386/i386-expand.c =================================================================== --- config/i386/i386-expand.c (revision 273492) +++ config/i386/i386-expand.c (working copy) @@ -1122,8 +1122,6 @@ ix86_split_idivmod (machine_mode mode, rtx operand rtx_insn *insn; rtx scratch, tmp0, tmp1, tmp2; rtx (*gen_divmod4_1) (rtx, rtx, rtx, rtx); - rtx (*gen_zero_extend) (rtx, rtx); - rtx (*gen_test_ccno_1) (rtx, rtx); switch (mode) { @@ -1135,21 +1133,16 @@ ix86_split_idivmod (machine_mode mode, rtx operand else gen_divmod4_1 = unsigned_p ? gen_udivmodsi4_zext_2 : gen_divmodsi4_zext_2; - gen_zero_extend = gen_zero_extendqisi2; } else - { - gen_divmod4_1 - = unsigned_p ? gen_udivmodsi4_zext_1 : gen_divmodsi4_zext_1; - gen_zero_extend = gen_zero_extendqidi2; - } - gen_test_ccno_1 = gen_testsi_ccno_1; + gen_divmod4_1 + = unsigned_p ? gen_udivmodsi4_zext_1 : gen_divmodsi4_zext_1; break; + case E_DImode: gen_divmod4_1 = unsigned_p ? gen_udivmoddi4_1 : gen_divmoddi4_1; - gen_test_ccno_1 = gen_testdi_ccno_1; - gen_zero_extend = gen_zero_extendqidi2; break; + default: gcc_unreachable (); } @@ -1164,7 +1157,7 @@ ix86_split_idivmod (machine_mode mode, rtx operand emit_move_insn (scratch, operands[2]); scratch = expand_simple_binop (mode, IOR, scratch, operands[3], scratch, 1, OPTAB_DIRECT); - emit_insn (gen_test_ccno_1 (scratch, GEN_INT (-0x100))); + emit_insn (gen_test_ccno_1 (mode, scratch, GEN_INT (-0x100))); tmp0 = gen_rtx_REG (CCNOmode, FLAGS_REG); tmp0 = gen_rtx_EQ (VOIDmode, tmp0, const0_rtx); tmp0 = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp0, @@ -1227,7 +1220,9 @@ ix86_split_idivmod (machine_mode mode, rtx operand /* Zero extend quotient from AL. */ tmp1 = gen_lowpart (QImode, tmp0); - insn = emit_insn (gen_zero_extend (operands[0], tmp1)); + insn = emit_insn (gen_extend_insn + (operands[0], tmp1, + GET_MODE (operands[0]), QImode, 1)); set_unique_reg_note (insn, REG_EQUAL, div); emit_label (end_label); Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 273492) +++ config/i386/i386.md (working copy) @@ -8124,7 +8124,7 @@ ;; On Pentium, "test imm, reg" is pairable only with eax, ax, and al. ;; Note that this excludes ah. -(define_expand "test<mode>_ccno_1" +(define_expand "@test<mode>_ccno_1" [(set (reg:CCNO FLAGS_REG) (compare:CCNO (and:SWI48 @@ -8142,19 +8142,15 @@ [(set (reg FLAGS_REG) (compare (and:DI - (match_operand:DI 0 "nonimmediate_operand" "%!*a,r,!*a,r,rm") - (match_operand:DI 1 "x86_64_szext_nonmemory_operand" "Z,Z,e,e,re")) + (match_operand:DI 0 "nonimmediate_operand" "r,rm") + (match_operand:DI 1 "x86_64_szext_nonmemory_operand" "Z,re")) (const_int 0)))] "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)" "@ test{l}\t{%k1, %k0|%k0, %k1} - test{l}\t{%k1, %k0|%k0, %k1} - test{q}\t{%1, %0|%0, %1} - test{q}\t{%1, %0|%0, %1} test{q}\t{%1, %0|%0, %1}" [(set_attr "type" "test") - (set_attr "modrm" "0,1,0,1,1") - (set_attr "mode" "SI,SI,DI,DI,DI")]) + (set_attr "mode" "SI,DI")]) (define_insn "*testqi_1_maybe_si" [(set (reg FLAGS_REG) @@ -8177,7 +8173,6 @@ return "test{b}\t{%1, %0|%0, %1}"; } [(set_attr "type" "test") - (set_attr "modrm" "0,1,1,1") (set_attr "mode" "QI,QI,QI,SI") (set_attr "pent_pair" "uv,np,uv,np")]) @@ -8191,7 +8186,6 @@ "ix86_match_ccmode (insn, CCNOmode)" "test{<imodesuffix>}\t{%1, %0|%0, %1}" [(set_attr "type" "test") - (set_attr "modrm" "0,1,1") (set_attr "mode" "<MODE>") (set_attr "pent_pair" "uv,np,uv")])