[llvm] aaccc98 - [M68k][GloballSel] LegalizerInfo implementation
Anshil Gandhi via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 12:00:59 PDT 2021
Author: Sushma Unnibhavi
Date: 2021-07-15T13:00:43-06:00
New Revision: aaccc985a88db4fb7ae4be341db62bb1fe974102
URL: https://github.com/llvm/llvm-project/commit/aaccc985a88db4fb7ae4be341db62bb1fe974102
DIFF: https://github.com/llvm/llvm-project/commit/aaccc985a88db4fb7ae4be341db62bb1fe974102.diff
LOG: [M68k][GloballSel] LegalizerInfo implementation
Added rules for G_ADD, G_SUB, G_MUL, G_UDIV to be legal.
Differential Revision: https://reviews.llvm.org/D105536
Added:
llvm/test/CodeGen/M68k/GlobalISel/arithmetic.ll
Modified:
llvm/lib/Target/M68k/GlSel/M68kLegalizerInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/M68k/GlSel/M68kLegalizerInfo.cpp b/llvm/lib/Target/M68k/GlSel/M68kLegalizerInfo.cpp
index f1f810918d15c..bcbe62816beb4 100644
--- a/llvm/lib/Target/M68k/GlSel/M68kLegalizerInfo.cpp
+++ b/llvm/lib/Target/M68k/GlSel/M68kLegalizerInfo.cpp
@@ -20,5 +20,14 @@
using namespace llvm;
M68kLegalizerInfo::M68kLegalizerInfo(const M68kSubtarget &ST) {
+ using namespace TargetOpcode;
+ const LLT S32 = LLT::scalar(32);
+ const LLT P0 = LLT::pointer(0, 32);
+ getActionDefinitionsBuilder(G_LOAD).legalFor({S32});
+ getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({P0});
+ getActionDefinitionsBuilder(G_ADD).legalFor({S32});
+ getActionDefinitionsBuilder(G_SUB).legalFor({S32});
+ getActionDefinitionsBuilder(G_MUL).legalFor({S32});
+ getActionDefinitionsBuilder(G_UDIV).legalFor({S32});
getLegacyLegalizerInfo().computeTables();
}
diff --git a/llvm/test/CodeGen/M68k/GlobalISel/arithmetic.ll b/llvm/test/CodeGen/M68k/GlobalISel/arithmetic.ll
new file mode 100644
index 0000000000000..f50070b023bec
--- /dev/null
+++ b/llvm/test/CodeGen/M68k/GlobalISel/arithmetic.ll
@@ -0,0 +1,57 @@
+; RUN: llc -mtriple=m68k -global-isel -stop-after=legalizer < %s | FileCheck %s
+
+define i32 @test_add(i32 %x, i32 %y) {
+ ; CHECK-LABEL: name: test_add
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK: [[G_F_I1:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I1]](p0)
+ ; CHECK: [[G_F_I2:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD2:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I2]](p0)
+ ; CHECK: [[G_ADD1:%[0-9]+]]:_(s32) = G_ADD [[G_LOAD1]], [[G_LOAD2]]
+ ; CHECK: $d0 = COPY [[G_ADD1]](s32)
+ ; CHECK: RTS implicit $d0
+ %sum = add i32 %x, %y
+ ret i32 %sum
+}
+
+define i32 @test_sub(i32 %x, i32 %y) {
+ ; CHECK-LABEL: name: test_sub
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK: [[G_F_I1:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I1]](p0)
+ ; CHECK: [[G_F_I2:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD2:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I2]](p0)
+ ; CHECK: [[G_SUB1:%[0-9]+]]:_(s32) = G_SUB [[G_LOAD1]], [[G_LOAD2]]
+ ; CHECK: $d0 = COPY [[G_SUB1]](s32)
+ ; CHECK: RTS implicit $d0
+ %
diff = sub i32 %x, %y
+ ret i32 %
diff
+}
+
+define i32 @test_mul(i32 %x, i32 %y) {
+ ; CHECK-LABEL: name: test_mul
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK: [[G_F_I1:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I1]](p0)
+ ; CHECK: [[G_F_I2:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD2:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I2]](p0)
+ ; CHECK: [[G_MUL1:%[0-9]+]]:_(s32) = G_MUL [[G_LOAD1]], [[G_LOAD2]]
+ ; CHECK: $d0 = COPY [[G_MUL1]](s32)
+ ; CHECK: RTS implicit $d0
+ %prod = mul i32 %x, %y
+ ret i32 %prod
+}
+
+define i32 @test_udiv(i32 %x, i32 %y) {
+ ; CHECK-LABEL: name: test_udiv
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK: [[G_F_I1:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I1]](p0)
+ ; CHECK: [[G_F_I2:%[0-9]+]]:_(p0) = G_FRAME_INDEX
+ ; CHECK: [[G_LOAD2:%[0-9]+]]:_(s32) = G_LOAD [[G_F_I2]](p0)
+ ; CHECK: [[G_DIV1:%[0-9]+]]:_(s32) = G_UDIV [[G_LOAD1]], [[G_LOAD2]]
+ ; CHECK: $d0 = COPY [[G_DIV1]](s32)
+ ; CHECK: RTS implicit $d0
+ %div = udiv i32 %x, %y
+ ret i32 %div
+}
More information about the llvm-commits
mailing list