在 2022/7/7 上午10:23, Xi Ruoyao 写道:
We were generating some unnecessary instructions for integer division.
These two patches improve the code generation to compile

     template <class T> T div(T a, T b) { return a / b; }

into a single division instruction (along with a return instruction of
course) as we expected for T in {int32_t, uint32_t, int64_t}.

Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for trunk?

Xi Ruoyao (2):
   loongarch: add alternatives for idiv insns to improve code generation
   loongarch: avoid unnecessary sign-extend after 32-bit division

  gcc/config/loongarch/loongarch-protos.h    |  1 +
  gcc/config/loongarch/loongarch.cc          |  2 +-
  gcc/config/loongarch/loongarch.md          | 34 ++++++++++++++++------
  gcc/testsuite/gcc.target/loongarch/div-1.c |  9 ++++++
  gcc/testsuite/gcc.target/loongarch/div-2.c |  9 ++++++
  gcc/testsuite/gcc.target/loongarch/div-3.c |  9 ++++++
  gcc/testsuite/gcc.target/loongarch/div-4.c |  9 ++++++
  7 files changed, 63 insertions(+), 10 deletions(-)
  create mode 100644 gcc/testsuite/gcc.target/loongarch/div-1.c
  create mode 100644 gcc/testsuite/gcc.target/loongarch/div-2.c
  create mode 100644 gcc/testsuite/gcc.target/loongarch/div-3.c
  create mode 100644 gcc/testsuite/gcc.target/loongarch/div-4.c

I am testing the spec and it can be done today or tomorrow.

Reply via email to