[llvm] 4bd79ea - [M68k] Add pc-relative displacement (PCD) addressing mode for MOVSX
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 29 11:54:25 PST 2023
Author: Min-Yih Hsu
Date: 2023-12-29T11:52:49-08:00
New Revision: 4bd79ea3fe15c55852e8ec046db4a1513c9ebc1f
URL: https://github.com/llvm/llvm-project/commit/4bd79ea3fe15c55852e8ec046db4a1513c9ebc1f
DIFF: https://github.com/llvm/llvm-project/commit/4bd79ea3fe15c55852e8ec046db4a1513c9ebc1f.diff
LOG: [M68k] Add pc-relative displacement (PCD) addressing mode for MOVSX
And disable offset folding altogether since we cannot always gain the
precise offset there to see if that fits into a certain size of
displacement.
Added:
llvm/test/CodeGen/M68k/global-address.ll
Modified:
llvm/lib/Target/M68k/M68kExpandPseudo.cpp
llvm/lib/Target/M68k/M68kISelLowering.h
llvm/lib/Target/M68k/M68kInstrData.td
Removed:
################################################################################
diff --git a/llvm/lib/Target/M68k/M68kExpandPseudo.cpp b/llvm/lib/Target/M68k/M68kExpandPseudo.cpp
index 7bd3821077737e..7fcc65beaa653b 100644
--- a/llvm/lib/Target/M68k/M68kExpandPseudo.cpp
+++ b/llvm/lib/Target/M68k/M68kExpandPseudo.cpp
@@ -161,6 +161,16 @@ bool M68kExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
return TII->ExpandMOVSZX_RM(MIB, false, TII->get(M68k::MOV16rf), MVT::i32,
MVT::i16);
+ case M68k::MOVSXd16q8:
+ return TII->ExpandMOVSZX_RM(MIB, true, TII->get(M68k::MOV8dq), MVT::i16,
+ MVT::i8);
+ case M68k::MOVSXd32q8:
+ return TII->ExpandMOVSZX_RM(MIB, true, TII->get(M68k::MOV8dq), MVT::i32,
+ MVT::i8);
+ case M68k::MOVSXd32q16:
+ return TII->ExpandMOVSZX_RM(MIB, true, TII->get(M68k::MOV16dq), MVT::i32,
+ MVT::i16);
+
case M68k::MOVZXd16q8:
return TII->ExpandMOVSZX_RM(MIB, false, TII->get(M68k::MOV8dq), MVT::i16,
MVT::i8);
diff --git a/llvm/lib/Target/M68k/M68kISelLowering.h b/llvm/lib/Target/M68k/M68kISelLowering.h
index 02427a4e749e09..d00907775f9280 100644
--- a/llvm/lib/Target/M68k/M68kISelLowering.h
+++ b/llvm/lib/Target/M68k/M68kISelLowering.h
@@ -194,6 +194,15 @@ class M68kTargetLowering : public TargetLowering {
unsigned GetAlignedArgumentStackSize(unsigned StackSize,
SelectionDAG &DAG) const;
+ bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override {
+ // In many cases, `GA` doesn't give the correct offset to fold. It's
+ // hard to know if the real offset actually fits into the displacement
+ // of the perspective addressing mode.
+ // Thus, we disable offset folding altogether and leave that to ISel
+ // patterns.
+ return false;
+ }
+
SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;
/// Emit a load of return address if tail call
diff --git a/llvm/lib/Target/M68k/M68kInstrData.td b/llvm/lib/Target/M68k/M68kInstrData.td
index 624093661d19f6..fa7e7aa0ed4619 100644
--- a/llvm/lib/Target/M68k/M68kInstrData.td
+++ b/llvm/lib/Target/M68k/M68kInstrData.td
@@ -554,18 +554,21 @@ def: Pat<(MxSExtLoadi16i8 MxCP_ARID:$src),
(EXTRACT_SUBREG (MOVSXd32p8 MxARID8:$src), MxSubRegIndex16Lo)>;
def: Pat<(MxSExtLoadi16i8 MxCP_ARII:$src),
(EXTRACT_SUBREG (MOVSXd32f8 MxARII8:$src), MxSubRegIndex16Lo)>;
+def: Pat<(MxSExtLoadi16i8 MxCP_PCD:$src), (MOVSXd16q8 MxPCD8:$src)>;
// i32 <- sext i8
def: Pat<(i32 (sext i8:$src)), (MOVSXd32d8 MxDRD8:$src)>;
def: Pat<(MxSExtLoadi32i8 MxCP_ARI :$src), (MOVSXd32j8 MxARI8 :$src)>;
def: Pat<(MxSExtLoadi32i8 MxCP_ARID:$src), (MOVSXd32p8 MxARID8:$src)>;
def: Pat<(MxSExtLoadi32i8 MxCP_ARII:$src), (MOVSXd32f8 MxARII8:$src)>;
+def: Pat<(MxSExtLoadi32i8 MxCP_PCD:$src), (MOVSXd32q8 MxPCD8:$src)>;
// i32 <- sext i16
def: Pat<(i32 (sext i16:$src)), (MOVSXd32d16 MxDRD16:$src)>;
def: Pat<(MxSExtLoadi32i16 MxCP_ARI :$src), (MOVSXd32j16 MxARI16 :$src)>;
def: Pat<(MxSExtLoadi32i16 MxCP_ARID:$src), (MOVSXd32p16 MxARID16:$src)>;
def: Pat<(MxSExtLoadi32i16 MxCP_ARII:$src), (MOVSXd32f16 MxARII16:$src)>;
+def: Pat<(MxSExtLoadi32i16 MxCP_PCD:$src), (MOVSXd32q16 MxPCD16:$src)>;
// i16 <- zext i8
def: Pat<(i16 (zext i8:$src)),
diff --git a/llvm/test/CodeGen/M68k/global-address.ll b/llvm/test/CodeGen/M68k/global-address.ll
new file mode 100644
index 00000000000000..8af37f9f733f55
--- /dev/null
+++ b/llvm/test/CodeGen/M68k/global-address.ll
@@ -0,0 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: llc -mtriple=m68k < %s | FileCheck %s
+
+ at VBRTag = external dso_local global [2147483647 x i8]
+
+define i1 @folded_offset(i32 %conv29) {
+; CHECK-LABEL: folded_offset:
+; CHECK: .cfi_startproc
+; CHECK-NEXT: ; %bb.0: ; %entry
+; CHECK-NEXT: move.b (VBRTag+1,%pc), %d0
+; CHECK-NEXT: ext.w %d0
+; CHECK-NEXT: ext.l %d0
+; CHECK-NEXT: sub.l (4,%sp), %d0
+; CHECK-NEXT: seq %d0
+; CHECK-NEXT: rts
+entry:
+ %0 = load i8, ptr getelementptr inbounds ([2147483647 x i8], ptr @VBRTag, i32 0, i32 1), align 1
+ %conv30 = sext i8 %0 to i32
+ %cmp31.not = icmp eq i32 %conv30, %conv29
+ ret i1 %cmp31.not
+}
+
+define i1 @non_folded_offset(i32 %conv29) {
+; CHECK-LABEL: non_folded_offset:
+; CHECK: .cfi_startproc
+; CHECK-NEXT: ; %bb.0: ; %entry
+; CHECK-NEXT: move.l #2147483645, %d0
+; CHECK-NEXT: lea (VBRTag,%pc), %a0
+; CHECK-NEXT: move.b (0,%a0,%d0), %d0
+; CHECK-NEXT: ext.w %d0
+; CHECK-NEXT: ext.l %d0
+; CHECK-NEXT: sub.l (4,%sp), %d0
+; CHECK-NEXT: seq %d0
+; CHECK-NEXT: rts
+entry:
+ %0 = load i8, ptr getelementptr inbounds ([2147483647 x i8], ptr @VBRTag, i32 0, i32 2147483645), align 1
+ %conv30 = sext i8 %0 to i32
+ %cmp31.not = icmp eq i32 %conv30, %conv29
+ ret i1 %cmp31.not
+}
More information about the llvm-commits
mailing list