diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 6bca2ed3993..5c0445dd879 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -752,6 +752,7 @@ { rtx reg1 = gen_reg_rtx (DImode); rtx reg2 = gen_reg_rtx (DImode); + rtx rd = gen_reg_rtx (DImode); operands[1] = gen_rtx_SIGN_EXTEND (word_mode, operands[1]); operands[2] = gen_rtx_SIGN_EXTEND (word_mode, operands[2]); @@ -759,7 +760,9 @@ emit_insn (gen_rtx_SET (reg1, operands[1])); emit_insn (gen_rtx_SET (reg2, operands[2])); - emit_insn (gen_di3_fake (operands[0], reg1, reg2)); + emit_insn (gen_di3_fake (rd, reg1, reg2)); + emit_insn (gen_rtx_SET (operands[0], + simplify_gen_subreg (SImode, rd, DImode, 0))); DONE; } }) @@ -781,9 +784,10 @@ (const_string "no")))]) (define_insn "di3_fake" - [(set (match_operand:SI 0 "register_operand" "=r,&r,&r") - (any_div:SI (match_operand:DI 1 "register_operand" "r,r,0") - (match_operand:DI 2 "register_operand" "r,r,r")))] + [(set (match_operand:DI 0 "register_operand" "=r,&r,&r") + (sign_extend:DI + (any_div:SI (match_operand:DI 1 "register_operand" "r,r,0") + (match_operand:DI 2 "register_operand" "r,r,r"))))] "" { return loongarch_output_division (".w\t%0,%1,%2", operands); diff --git a/gcc/testsuite/gcc.target/loongarch/div-4.c b/gcc/testsuite/gcc.target/loongarch/div-4.c new file mode 100644 index 00000000000..a52f87d6caf --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/div-4.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "slli" } } */ + +int +div(int a, int b) +{ + return a / b; +}