[llvm] [AArch64] Fold UBFMXri to UBFMWri when it's an LSR or LSL alias (PR #106968)
Csanád Hajdú via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 01:08:45 PDT 2024
================
@@ -715,6 +719,45 @@ bool AArch64MIPeepholeOpt::visitFMOVDr(MachineInstr &MI) {
return true;
}
+bool AArch64MIPeepholeOpt::visitUBFMXri(MachineInstr &MI) {
+ // Check if the instruction is equivalent to a 32 bit LSR or LSL alias of
+ // UBFM, and replace the UBFMXri instruction with its 32 bit variant, UBFMWri.
+ int64_t Immr = MI.getOperand(2).getImm();
+ int64_t Imms = MI.getOperand(3).getImm();
+
+ bool IsLSR = Imms == 31 && Immr <= Imms;
+ bool IsLSL = Immr == Imms + 33;
+ if (IsLSR || IsLSL) {
+ if (IsLSL) {
+ Immr -= 32;
+ }
+
+ const TargetRegisterClass *RegClass64 =
+ TII->getRegClass(TII->get(MI.getOpcode()), 0, TRI, *MI.getMF());
+ const TargetRegisterClass *RegClass32 =
+ TRI->getSubRegisterClass(RegClass64, AArch64::sub_32);
+
+ Register DstReg32 = MRI->createVirtualRegister(RegClass32);
+ Register DstReg64 = MI.getOperand(0).getReg();
+ Register SrcReg = MI.getOperand(1).getReg();
+
+ BuildMI(*MI.getParent(), MI, MI.getDebugLoc(), TII->get(AArch64::UBFMWri),
+ DstReg32)
+ .addReg(SrcReg, 0, AArch64::sub_32)
----------------
Il-Capitano wrote:
I added the extra COPY with the latest commit.
https://github.com/llvm/llvm-project/pull/106968
More information about the llvm-commits
mailing list