Skip to content

[LoongArch] Enable AllNBitUsers checking for {DIV,MOD}.W{U} with div32 enabled #118776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

heiher
Copy link
Member

@heiher heiher commented Dec 5, 2024

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2024

@llvm/pr-subscribers-backend-loongarch

Author: hev (heiher)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/118776.diff

2 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp (+9-5)
  • (modified) llvm/test/CodeGen/LoongArch/ir-instruction/sdiv-udiv-srem-urem-div32.ll (+3-4)
diff --git a/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp b/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp
index ab90409fdf47d0..51e5e288a25124 100644
--- a/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp
@@ -139,11 +139,6 @@ static bool hasAllNBitUsers(const MachineInstr &OrigMI,
       case LoongArch::MULH_WU:
       case LoongArch::MULW_D_W:
       case LoongArch::MULW_D_WU:
-      // TODO: {DIV,MOD}.{W,WU} consumes the upper 32 bits before LA664+.
-      // case LoongArch::DIV_W:
-      // case LoongArch::DIV_WU:
-      // case LoongArch::MOD_W:
-      // case LoongArch::MOD_WU:
       case LoongArch::SLL_W:
       case LoongArch::SLLI_W:
       case LoongArch::SRL_W:
@@ -170,6 +165,15 @@ static bool hasAllNBitUsers(const MachineInstr &OrigMI,
         if (Bits >= 32)
           break;
         return false;
+      // {DIV,MOD}.W{U} consumes the upper 32 bits if the div32
+      // feature is not enabled.
+      case LoongArch::DIV_W:
+      case LoongArch::DIV_WU:
+      case LoongArch::MOD_W:
+      case LoongArch::MOD_WU:
+        if (Bits >= 32 && ST.hasDiv32())
+          break;
+        return false;
       case LoongArch::MOVGR2CF:
         if (Bits >= 1)
           break;
diff --git a/llvm/test/CodeGen/LoongArch/ir-instruction/sdiv-udiv-srem-urem-div32.ll b/llvm/test/CodeGen/LoongArch/ir-instruction/sdiv-udiv-srem-urem-div32.ll
index 7e7518154e8397..9276195b6fa0b4 100644
--- a/llvm/test/CodeGen/LoongArch/ir-instruction/sdiv-udiv-srem-urem-div32.ll
+++ b/llvm/test/CodeGen/LoongArch/ir-instruction/sdiv-udiv-srem-urem-div32.ll
@@ -84,10 +84,9 @@ define signext i32 @sextw_rmv(i32 signext %a, i32 signext %b, i32 signext %c) {
 ;
 ; LA64-DIV32-LABEL: sextw_rmv:
 ; LA64-DIV32:       # %bb.0: # %entry
-; LA64-DIV32-NEXT:    mul.d $a0, $a1, $a0
-; LA64-DIV32-NEXT:    addi.w $a1, $a0, 0
-; LA64-DIV32-NEXT:    div.w $a0, $a2, $a0
-; LA64-DIV32-NEXT:    sltu $a0, $a0, $a1
+; LA64-DIV32-NEXT:    mul.w $a0, $a1, $a0
+; LA64-DIV32-NEXT:    div.w $a1, $a2, $a0
+; LA64-DIV32-NEXT:    sltu $a0, $a1, $a0
 ; LA64-DIV32-NEXT:    ret
 entry:
   %mul = mul nsw i32 %b, %a

@heiher heiher merged commit f6289f1 into llvm:main Dec 10, 2024
10 checks passed
@heiher heiher deleted the sextw-rmv-div32 branch December 10, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants