[llvm-branch-commits] [llvm] release/19.x: [LoongArch] Eliminate the redundant sign extension of division (#107971) (PR #107990)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 10 02:02:55 PDT 2024
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/107990
Backport 0f47e3aebdd2a4a938468a272ea4224552dbf176
Requested by: @heiher
>From e27281dd8fdf476505f6faaa9f9c2eda8d023cbb Mon Sep 17 00:00:00 2001
From: hev <wangrui at loongson.cn>
Date: Tue, 10 Sep 2024 16:52:21 +0800
Subject: [PATCH] [LoongArch] Eliminate the redundant sign extension of
division (#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: #107946
(cherry picked from commit 0f47e3aebdd2a4a938468a272ea4224552dbf176)
---
llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
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;
More information about the llvm-branch-commits
mailing list