Skip to content

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Sep 10, 2024

Backport 0f47e3a

Requested by: @heiher

@llvmbot llvmbot added this to the LLVM 19.X Release milestone Sep 10, 2024
@llvmbot
Copy link
Member Author

llvmbot commented Sep 10, 2024

@SixWeining What do you think about merging this PR to the release branch?

@llvmbot
Copy link
Member Author

llvmbot commented Sep 10, 2024

@llvm/pr-subscribers-backend-loongarch

Author: None (llvmbot)

Changes

Backport 0f47e3a

Requested by: @heiher


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

1 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp (+15)
diff --git a/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp b/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp
index abac69054f3b91..ab90409fdf47d0 100644
--- a/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp
@@ -637,6 +637,19 @@ static bool isSignExtendedW(Register SrcReg, const LoongArchSubtarget &ST,
         break;
       }
       return false;
+    // If all incoming values are sign-extended and all users only use
+    // the lower 32 bits, then convert them to W versions.
+    case LoongArch::DIV_D: {
+      if (!AddRegToWorkList(MI->getOperand(1).getReg()))
+        return false;
+      if (!AddRegToWorkList(MI->getOperand(2).getReg()))
+        return false;
+      if (hasAllWUsers(*MI, ST, MRI)) {
+        FixableDef.insert(MI);
+        break;
+      }
+      return false;
+    }
     }
   }
 
@@ -651,6 +664,8 @@ static unsigned getWOp(unsigned Opcode) {
     return LoongArch::ADDI_W;
   case LoongArch::ADD_D:
     return LoongArch::ADD_W;
+  case LoongArch::DIV_D:
+    return LoongArch::DIV_W;
   case LoongArch::LD_D:
   case LoongArch::LD_WU:
     return LoongArch::LD_W;

@heiher
Copy link
Member

heiher commented Sep 10, 2024

It seems that the patch created by the bot is incomplete. I'm not sure if it will automatically update after #107945 is merged. If not, it may be necessary to re-trigger the cherry-pick.

@tru
Copy link
Collaborator

tru commented Sep 13, 2024

Just re-run the cherry-pick comment on the updated SHA.

…107971)

If all incoming values of `div.d` are sign-extended and all users only
use the lower 32 bits, then convert them to W versions.

Fixes: llvm#107946
(cherry picked from commit 0f47e3a)
@tru tru merged commit d752f29 into llvm:release/19.x Sep 16, 2024
5 of 10 checks passed
Copy link

@heiher (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants