diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 0626752..fabddc2 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -4756,6 +4756,38 @@ (if_then_else (eq_attr "prefix_0f" "0") (const_string "0") (const_string "1")))]) + +(define_insn_and_split "extendditi2" + [(set (match_operand:TI 0 "register_operand" "=r") + (sign_extend:TI (match_operand:DI 1 "register_operand" "r"))) + (clobber (reg:CC FLAGS_REG))] + "TARGET_64BIT" + "#" + "&& reload_completed" + [(const_int 0)] +{ + split_double_mode (TImode, &operands[0], 1, &operands[2], &operands[3]); + if (REGNO (operands[1]) != REGNO (operands[2])) + emit_move_insn (operands[2], operands[1]); + + rtx src = operands[1]; + if (REGNO (operands[2]) == AX_REG) + src = operands[2]; + + /* Generate a cltd if possible and doing so it profitable. */ + if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD) + && REGNO (operands[3]) == DX_REG + && REGNO (src) == AX_REG) + { + emit_insn (gen_ashrdi3_cvt (operands[3], src, GEN_INT (63))); + } + else + { + if (REGNO (operands[1]) != REGNO (operands[3])) + emit_move_insn (operands[3], operands[1]); + emit_insn (gen_ashrdi3_cvt (operands[3], operands[3], GEN_INT (63))); + } +}) ;; Conversions between float and double. diff --git a/gcc/testsuite/gcc.target/i386/extendditi2-1.c b/gcc/testsuite/gcc.target/i386/extendditi2-1.c new file mode 100644 index 0000000..846afef --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/extendditi2-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2" } */ + +__int128 foo(long long x) +{ + return (__int128)x; +} +/* { dg-final { scan-assembler "cqto" } } */ diff --git a/gcc/testsuite/gcc.target/i386/extendditi2-2.c b/gcc/testsuite/gcc.target/i386/extendditi2-2.c new file mode 100644 index 0000000..dbfa6fb --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/extendditi2-2.c @@ -0,0 +1,13 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2" } */ + +__int128 foo(__int128 a, long long b) { + a += ((__int128)b) << 70; + return a; +} + +__int128 bar(__int128 a, unsigned long long b) { + a += ((__int128)b) << 70; + return a; +} +/* { dg-final { scan-assembler-not "movq" } } */