[llvm] 6eb36ae - [RISCV][GISel] Mark G_GLOBAL_VALUE as legal.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 09:30:39 PDT 2023
Author: Craig Topper
Date: 2023-08-15T09:26:29-07:00
New Revision: 6eb36aed86ea276695697093eb8136554c29286b
URL: https://github.com/llvm/llvm-project/commit/6eb36aed86ea276695697093eb8136554c29286b
DIFF: https://github.com/llvm/llvm-project/commit/6eb36aed86ea276695697093eb8136554c29286b.diff
LOG: [RISCV][GISel] Mark G_GLOBAL_VALUE as legal.
Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D157950
Added:
llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-global.mir
llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-global.mir
Modified:
llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index a787f08fd2a878..37db84fadedecf 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -89,5 +89,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) {
.widenScalarToNextPow2(0)
.clampScalar(0, XLenLLT, XLenLLT);
+ getActionDefinitionsBuilder(G_GLOBAL_VALUE)
+ .legalFor({p0});
+
getLegacyLegalizerInfo().computeTables();
}
diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-global.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-global.mir
new file mode 100644
index 00000000000000..8e7daa60aa8deb
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-global.mir
@@ -0,0 +1,33 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=riscv32 -run-pass=legalizer %s -o - | FileCheck %s
+
+--- |
+ @var = global i32 0
+
+ define ptr @test_global() {
+ ret ptr @var
+ }
+
+...
+---
+name: test_global
+alignment: 4
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: _ }
+frameInfo:
+ maxAlignment: 1
+machineFunctionInfo:
+ varArgsFrameIndex: 0
+ varArgsSaveSize: 0
+body: |
+ bb.1 (%ir-block.0):
+ ; CHECK-LABEL: name: test_global
+ ; CHECK: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var
+ ; CHECK-NEXT: $x10 = COPY [[GV]](p0)
+ ; CHECK-NEXT: PseudoRET implicit $x10
+ %0:_(p0) = G_GLOBAL_VALUE @var
+ $x10 = COPY %0(p0)
+ PseudoRET implicit $x10
+
+...
diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-global.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-global.mir
new file mode 100644
index 00000000000000..9e501214083864
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-global.mir
@@ -0,0 +1,33 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=riscv64 -run-pass=legalizer %s -o - | FileCheck %s
+
+--- |
+ @var = global i32 0
+
+ define ptr @test_global() {
+ ret ptr @var
+ }
+
+...
+---
+name: test_global
+alignment: 4
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: _ }
+frameInfo:
+ maxAlignment: 1
+machineFunctionInfo:
+ varArgsFrameIndex: 0
+ varArgsSaveSize: 0
+body: |
+ bb.1 (%ir-block.0):
+ ; CHECK-LABEL: name: test_global
+ ; CHECK: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var
+ ; CHECK-NEXT: $x10 = COPY [[GV]](p0)
+ ; CHECK-NEXT: PseudoRET implicit $x10
+ %0:_(p0) = G_GLOBAL_VALUE @var
+ $x10 = COPY %0(p0)
+ PseudoRET implicit $x10
+
+...
More information about the llvm-commits
mailing list