[llvm] [GlobalISel] Catching inconsistencies in load memory, result, and range metadata type (PR #121247)
Renat Idrisov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 15 07:07:00 PST 2025
https://github.com/parsifal-47 updated https://github.com/llvm/llvm-project/pull/121247
>From d18e4f72c101adfd1cda014dd2c7f1b9e8d6f512 Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Sat, 28 Dec 2024 04:07:30 +0000
Subject: [PATCH 01/11] Catching inconsistencies in load memory, result, and
range metadata type
---
llvm/lib/CodeGen/MachineVerifier.cpp | 6 +++++
.../test_g_load_vector_to_scalar.mir | 25 +++++++++++++++++++
2 files changed, 31 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index bec36b728ae328..1866d3ae2b285a 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1274,6 +1274,12 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
if (TypeSize::isKnownGT(MMO.getSize().getValue(),
ValTy.getSizeInBytes()))
report("load memory size cannot exceed result size", MI);
+
+ if (MMO.getRanges() && (ValTy.isVector() != MMO.getType().isVector())) {
+ report("scalar operands cannot be loaded into vector values and vice "
+ "versa",
+ MI);
+ }
} else if (MI->getOpcode() == TargetOpcode::G_STORE) {
if (TypeSize::isKnownLT(ValTy.getSizeInBytes(),
MMO.getSize().getValue()))
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir
new file mode 100644
index 00000000000000..95429127c30d0c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir
@@ -0,0 +1,25 @@
+# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=amdgpu-prelegalizer-combiner -verify-machineinstrs %s -o -
+--- |
+ define void @range_metadata_sext_i33_signed_range_i64_load_as_v2i32() {
+ ret void
+ }
+
+ !1 = !{i64 -8589934591, i64 8589934592}
+
+...
+---
+name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0, $vgpr1
+
+ %1:_(s32) = COPY $vgpr0
+ %2:_(s32) = COPY $vgpr1
+ %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
+ ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
+ %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
+ $vgpr0_vgpr1 = COPY %3
+ SI_RETURN implicit $vgpr0_vgpr1
+
+...
>From b76c3dfb3475e44d8c17a028f41f0223ddca1267 Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Sun, 5 Jan 2025 15:53:04 +0000
Subject: [PATCH 02/11] Moving test case to proper location
---
.../test_g_load_vector_to_scalar.mir | 25 -------
.../test_g_load_vector_to_scalar.mir | 71 +++++++++++++++++++
2 files changed, 71 insertions(+), 25 deletions(-)
delete mode 100644 llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir
create mode 100644 llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir
deleted file mode 100644
index 95429127c30d0c..00000000000000
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/test_g_load_vector_to_scalar.mir
+++ /dev/null
@@ -1,25 +0,0 @@
-# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=amdgpu-prelegalizer-combiner -verify-machineinstrs %s -o -
---- |
- define void @range_metadata_sext_i33_signed_range_i64_load_as_v2i32() {
- ret void
- }
-
- !1 = !{i64 -8589934591, i64 8589934592}
-
-...
----
-name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
-tracksRegLiveness: true
-body: |
- bb.0:
- liveins: $vgpr0, $vgpr1
-
- %1:_(s32) = COPY $vgpr0
- %2:_(s32) = COPY $vgpr1
- %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
- ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
- %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
- $vgpr0_vgpr1 = COPY %3
- SI_RETURN implicit $vgpr0_vgpr1
-
-...
diff --git a/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir b/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
new file mode 100644
index 00000000000000..b255c0e5cd4021
--- /dev/null
+++ b/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
@@ -0,0 +1,71 @@
+# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=none %s -o -
+--- |
+ define void @range_metadata_sext_i8_signed_range_i64_load_as_v2i32() {
+ ret void
+ }
+
+ define void @range_metadata_sext_i8_signed_range_i64_load_as_v2i32_extractlo() {
+ ret void
+ }
+
+ define void @range_metadata_sext_i33_signed_range_i64_load_as_v2i32() {
+ ret void
+ }
+
+ !0 = !{i64 -4294967295, i64 4294967296}
+ !1 = !{i64 -8589934591, i64 8589934592}
+
+...
+---
+name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0, $vgpr1
+
+ %1:_(s32) = COPY $vgpr0
+ %2:_(s32) = COPY $vgpr1
+ %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
+ ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
+ %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
+ $vgpr0_vgpr1 = COPY %3
+ SI_RETURN implicit $vgpr0_vgpr1
+
+...
+
+---
+name: range_metadata_sext_i8_signed_range_i64_load_as_v2i32_extractlo
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0, $vgpr1
+
+ %1:_(s32) = COPY $vgpr0
+ %2:_(s32) = COPY $vgpr1
+ %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
+ ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
+ %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
+ %zero:_(s32) = G_CONSTANT i32 0
+ %extract:_(s32) = G_EXTRACT_VECTOR_ELT %3, %zero
+ %6:_(s32) = G_SEXT_INREG %zero, 9
+ $vgpr0 = COPY %6
+ SI_RETURN implicit $vgpr0, implicit $vgpr1
+
+...
+
+---
+name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0, $vgpr1
+
+ %1:_(s32) = COPY $vgpr0
+ %2:_(s32) = COPY $vgpr1
+ %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
+ ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
+ %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
+ $vgpr0_vgpr1 = COPY %3
+ SI_RETURN implicit $vgpr0_vgpr1
+
+...
>From b740e226c762079223b9aab6f5457d15a61f8ce8 Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Mon, 6 Jan 2025 15:58:17 +0000
Subject: [PATCH 03/11] Addressing review feedback
---
llvm/lib/CodeGen/MachineVerifier.cpp | 16 +++++++++++++---
.../test_g_load_vector_to_scalar.mir | 13 +++++++------
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 1866d3ae2b285a..5a02fde6383897 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1275,10 +1275,20 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
ValTy.getSizeInBytes()))
report("load memory size cannot exceed result size", MI);
- if (MMO.getRanges() && (ValTy.isVector() != MMO.getType().isVector())) {
- report("scalar operands cannot be loaded into vector values and vice "
- "versa",
+ if (MMO.getRanges()) {
+ auto operandBits = [](const MDOperand &o) -> unsigned {
+ ConstantInt *i = mdconst::dyn_extract<ConstantInt>(o);
+ if (!i->isNegative()) return i->getValue().getActiveBits();
+ APInt reversed(i->getValue());
+ reversed.negate();
+ return reversed.getActiveBits() + 1; // one more bit for the sign
+ };
+ unsigned bitsUsed = std::max(operandBits(MMO.getRanges()->getOperand(0)),
+ operandBits(MMO.getRanges()->getOperand(1)));
+ if (bitsUsed != ValTy.getScalarType().getSizeInBits()) {
+ report("range is incompatible with the value it gets assigned to",
MI);
+ }
}
} else if (MI->getOpcode() == TargetOpcode::G_STORE) {
if (TypeSize::isKnownLT(ValTy.getSizeInBytes(),
diff --git a/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir b/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
index b255c0e5cd4021..ea4c986a3428bb 100644
--- a/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
+++ b/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
@@ -26,7 +26,7 @@ body: |
%1:_(s32) = COPY $vgpr0
%2:_(s32) = COPY $vgpr1
%0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
- ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
+ ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
%3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
$vgpr0_vgpr1 = COPY %3
SI_RETURN implicit $vgpr0_vgpr1
@@ -43,7 +43,7 @@ body: |
%1:_(s32) = COPY $vgpr0
%2:_(s32) = COPY $vgpr1
%0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
- ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
+ ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
%3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
%zero:_(s32) = G_CONSTANT i32 0
%extract:_(s32) = G_EXTRACT_VECTOR_ELT %3, %zero
@@ -54,7 +54,7 @@ body: |
...
---
-name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
+name: range_metadata_sext_i8_signed_range_i64_load_as_v2i32
tracksRegLiveness: true
body: |
bb.0:
@@ -63,9 +63,10 @@ body: |
%1:_(s32) = COPY $vgpr0
%2:_(s32) = COPY $vgpr1
%0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
- ; CHECK: Bad machine code: scalar operands cannot be loaded into vector values
- %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
- $vgpr0_vgpr1 = COPY %3
+ ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
+ %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
+ %6:_(<2 x s32>) = G_SEXT_INREG %3, 9
+ $vgpr0_vgpr1 = COPY %6
SI_RETURN implicit $vgpr0_vgpr1
...
>From f935fc6ada4b1eec6e0a56aa69497fb787cb3e8b Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Mon, 6 Jan 2025 16:09:06 +0000
Subject: [PATCH 04/11] Formatting
---
llvm/lib/CodeGen/MachineVerifier.cpp | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 5a02fde6383897..d484c6811dda58 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1277,17 +1277,19 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
if (MMO.getRanges()) {
auto operandBits = [](const MDOperand &o) -> unsigned {
- ConstantInt *i = mdconst::dyn_extract<ConstantInt>(o);
- if (!i->isNegative()) return i->getValue().getActiveBits();
+ ConstantInt *i = mdconst::dyn_extract<ConstantInt>(o);
+ if (!i->isNegative())
+ return i->getValue().getActiveBits();
APInt reversed(i->getValue());
reversed.negate();
return reversed.getActiveBits() + 1; // one more bit for the sign
};
- unsigned bitsUsed = std::max(operandBits(MMO.getRanges()->getOperand(0)),
- operandBits(MMO.getRanges()->getOperand(1)));
+ unsigned bitsUsed =
+ std::max(operandBits(MMO.getRanges()->getOperand(0)),
+ operandBits(MMO.getRanges()->getOperand(1)));
if (bitsUsed != ValTy.getScalarType().getSizeInBits()) {
- report("range is incompatible with the value it gets assigned to",
- MI);
+ report("range is incompatible with the value it gets assigned to",
+ MI);
}
}
} else if (MI->getOpcode() == TargetOpcode::G_STORE) {
>From 21d6e71a9847edeed5ee540bcaf2708c68f0698f Mon Sep 17 00:00:00 2001
From: Renat Idrisov <4032256+parsifal-47 at users.noreply.github.com>
Date: Thu, 9 Jan 2025 07:26:25 -0800
Subject: [PATCH 05/11] Update
llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
---
llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir b/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
index ea4c986a3428bb..2b727a646be7f5 100644
--- a/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
+++ b/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
@@ -1,4 +1,4 @@
-# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=none %s -o -
+# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=none %s -filetype=null 2>&1 | FileCheck %s
--- |
define void @range_metadata_sext_i8_signed_range_i64_load_as_v2i32() {
ret void
>From ab0d2d529d1139670c301e6c81aa6a8318faacdd Mon Sep 17 00:00:00 2001
From: Renat Idrisov <4032256+parsifal-47 at users.noreply.github.com>
Date: Thu, 9 Jan 2025 07:26:34 -0800
Subject: [PATCH 06/11] Update llvm/lib/CodeGen/MachineVerifier.cpp
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
---
llvm/lib/CodeGen/MachineVerifier.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index d484c6811dda58..0762130c012205 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1277,7 +1277,7 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
if (MMO.getRanges()) {
auto operandBits = [](const MDOperand &o) -> unsigned {
- ConstantInt *i = mdconst::dyn_extract<ConstantInt>(o);
+ ConstantInt *i = mdconst::extract<ConstantInt>(o);
if (!i->isNegative())
return i->getValue().getActiveBits();
APInt reversed(i->getValue());
>From 21b9ca88ec40bb66c6ee5e44cf9a50e2b56e3efb Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Fri, 10 Jan 2025 15:32:38 +0000
Subject: [PATCH 07/11] Addressing review feedback
---
llvm/lib/CodeGen/MachineVerifier.cpp | 14 +---
.../legalize-load-memory-metadata.mir | 3 +-
...gbankselect-split-scalar-load-metadata.mir | 5 +-
.../test_g_incompatible_range.mir | 34 +++++++++
.../test_g_load_vector_to_scalar.mir | 72 -------------------
5 files changed, 41 insertions(+), 87 deletions(-)
create mode 100644 llvm/test/MachineVerifier/test_g_incompatible_range.mir
delete mode 100644 llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 0762130c012205..46606df00ea53b 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1276,18 +1276,8 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
report("load memory size cannot exceed result size", MI);
if (MMO.getRanges()) {
- auto operandBits = [](const MDOperand &o) -> unsigned {
- ConstantInt *i = mdconst::extract<ConstantInt>(o);
- if (!i->isNegative())
- return i->getValue().getActiveBits();
- APInt reversed(i->getValue());
- reversed.negate();
- return reversed.getActiveBits() + 1; // one more bit for the sign
- };
- unsigned bitsUsed =
- std::max(operandBits(MMO.getRanges()->getOperand(0)),
- operandBits(MMO.getRanges()->getOperand(1)));
- if (bitsUsed != ValTy.getScalarType().getSizeInBits()) {
+ ConstantInt *i = mdconst::extract<ConstantInt>(MMO.getRanges()->getOperand(0));
+ if (i->getIntegerType()->getBitWidth() != ValTy.getScalarType().getSizeInBits()) {
report("range is incompatible with the value it gets assigned to",
MI);
}
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-memory-metadata.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-memory-metadata.mir
index a862d4a9032e84..f0c4ea00ad4287 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-memory-metadata.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-memory-metadata.mir
@@ -30,6 +30,7 @@
!0 = !{i24 0, i24 1048575}
!1 = !{!"omnipotent char", !2}
!2 = !{!"Simple C/C++ TBAA"}
+ !3 = !{i32 0, i32 1048575}
...
# Make sure range metadata is not preserved when widening loads, but
@@ -67,7 +68,7 @@ body: |
; SI-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[COPY]](p1) :: (load (s32), !tbaa !1, addrspace 1)
; SI-NEXT: $vgpr0 = COPY [[LOAD]](s32)
%0:_(p1) = COPY $vgpr0_vgpr1
- %1:_(s32) = G_LOAD %0 :: (load (s24), align 4, addrspace 1, !range !0, !tbaa !1)
+ %1:_(s32) = G_LOAD %0 :: (load (s24), align 4, addrspace 1, !range !3, !tbaa !1)
$vgpr0 = COPY %1
...
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-split-scalar-load-metadata.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-split-scalar-load-metadata.mir
index c2dbeafce3df74..f954a4b4f98285 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-split-scalar-load-metadata.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-split-scalar-load-metadata.mir
@@ -17,6 +17,7 @@
!0 = !{i96 0, i96 9223372036854775808}
!1 = !{!"omnipotent char", !2}
!2 = !{!"Simple C/C++ TBAA"}
+ !3 = !{i32 0, i32 4294967295}
...
# Make sure range metadata is not preserved when widening loads, but
@@ -44,10 +45,10 @@ body: |
; GFX12: liveins: $sgpr0_sgpr1
; GFX12-NEXT: {{ $}}
; GFX12-NEXT: [[COPY:%[0-9]+]]:sgpr(p4) = COPY $sgpr0_sgpr1
- ; GFX12-NEXT: [[LOAD:%[0-9]+]]:sgpr(<3 x s32>) = G_LOAD [[COPY]](p4) :: (load (<3 x s32>), align 8, !range !0, addrspace 4)
+ ; GFX12-NEXT: [[LOAD:%[0-9]+]]:sgpr(<3 x s32>) = G_LOAD [[COPY]](p4) :: (load (<3 x s32>), align 8
; GFX12-NEXT: $sgpr0_sgpr1_sgpr2 = COPY [[LOAD]](<3 x s32>)
%0:_(p4) = COPY $sgpr0_sgpr1
- %1:_(<3 x s32>) = G_LOAD %0 :: (load (<3 x s32>), align 8, addrspace 4, !range !0)
+ %1:_(<3 x s32>) = G_LOAD %0 :: (load (<3 x s32>), align 8, addrspace 4, !range !3)
$sgpr0_sgpr1_sgpr2 = COPY %1
...
diff --git a/llvm/test/MachineVerifier/test_g_incompatible_range.mir b/llvm/test/MachineVerifier/test_g_incompatible_range.mir
new file mode 100644
index 00000000000000..14662a6b798827
--- /dev/null
+++ b/llvm/test/MachineVerifier/test_g_incompatible_range.mir
@@ -0,0 +1,34 @@
+# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=none %s -filetype=null 2>&1 | FileCheck %s
+--- |
+ define void @range_metadata_sext_i33_signed_range_i64_load_as_v2i32() {
+ ret void
+ }
+
+ !0 = !{i64 -4294967295, i64 4294967296}
+ !1 = !{i64 -8589934591, i64 8589934592}
+
+...
+---
+name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0, $vgpr1
+
+ %1:_(s32) = COPY $vgpr0
+ %2:_(s32) = COPY $vgpr1
+ %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
+
+ ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
+ %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
+
+ ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
+ %4:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
+
+ ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
+ %5:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
+
+ $vgpr0_vgpr1 = COPY %3
+ SI_RETURN implicit $vgpr0_vgpr1
+
+...
diff --git a/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir b/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
deleted file mode 100644
index 2b727a646be7f5..00000000000000
--- a/llvm/test/MachineVerifier/test_g_load_vector_to_scalar.mir
+++ /dev/null
@@ -1,72 +0,0 @@
-# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=none %s -filetype=null 2>&1 | FileCheck %s
---- |
- define void @range_metadata_sext_i8_signed_range_i64_load_as_v2i32() {
- ret void
- }
-
- define void @range_metadata_sext_i8_signed_range_i64_load_as_v2i32_extractlo() {
- ret void
- }
-
- define void @range_metadata_sext_i33_signed_range_i64_load_as_v2i32() {
- ret void
- }
-
- !0 = !{i64 -4294967295, i64 4294967296}
- !1 = !{i64 -8589934591, i64 8589934592}
-
-...
----
-name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
-tracksRegLiveness: true
-body: |
- bb.0:
- liveins: $vgpr0, $vgpr1
-
- %1:_(s32) = COPY $vgpr0
- %2:_(s32) = COPY $vgpr1
- %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
- ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
- %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !1, addrspace 1)
- $vgpr0_vgpr1 = COPY %3
- SI_RETURN implicit $vgpr0_vgpr1
-
-...
-
----
-name: range_metadata_sext_i8_signed_range_i64_load_as_v2i32_extractlo
-tracksRegLiveness: true
-body: |
- bb.0:
- liveins: $vgpr0, $vgpr1
-
- %1:_(s32) = COPY $vgpr0
- %2:_(s32) = COPY $vgpr1
- %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
- ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
- %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
- %zero:_(s32) = G_CONSTANT i32 0
- %extract:_(s32) = G_EXTRACT_VECTOR_ELT %3, %zero
- %6:_(s32) = G_SEXT_INREG %zero, 9
- $vgpr0 = COPY %6
- SI_RETURN implicit $vgpr0, implicit $vgpr1
-
-...
-
----
-name: range_metadata_sext_i8_signed_range_i64_load_as_v2i32
-tracksRegLiveness: true
-body: |
- bb.0:
- liveins: $vgpr0, $vgpr1
-
- %1:_(s32) = COPY $vgpr0
- %2:_(s32) = COPY $vgpr1
- %0:_(p1) = G_MERGE_VALUES %1(s32), %2(s32)
- ; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
- %3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
- %6:_(<2 x s32>) = G_SEXT_INREG %3, 9
- $vgpr0_vgpr1 = COPY %6
- SI_RETURN implicit $vgpr0_vgpr1
-
-...
>From 3a3233f018d8a7fce9ff741f61d997ba787f3b7a Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Fri, 10 Jan 2025 15:33:13 +0000
Subject: [PATCH 08/11] Formatting
---
llvm/lib/CodeGen/MachineVerifier.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 46606df00ea53b..54459a81deeb01 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1276,8 +1276,10 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
report("load memory size cannot exceed result size", MI);
if (MMO.getRanges()) {
- ConstantInt *i = mdconst::extract<ConstantInt>(MMO.getRanges()->getOperand(0));
- if (i->getIntegerType()->getBitWidth() != ValTy.getScalarType().getSizeInBits()) {
+ ConstantInt *i =
+ mdconst::extract<ConstantInt>(MMO.getRanges()->getOperand(0));
+ if (i->getIntegerType()->getBitWidth() !=
+ ValTy.getScalarType().getSizeInBits()) {
report("range is incompatible with the value it gets assigned to",
MI);
}
>From 8026866f7aeb7d53c4ad5b8b06dcfc76299d9678 Mon Sep 17 00:00:00 2001
From: Renat Idrisov <4032256+parsifal-47 at users.noreply.github.com>
Date: Wed, 15 Jan 2025 07:06:09 -0800
Subject: [PATCH 09/11] Update
llvm/test/MachineVerifier/test_g_incompatible_range.mir
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
---
llvm/test/MachineVerifier/test_g_incompatible_range.mir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/MachineVerifier/test_g_incompatible_range.mir b/llvm/test/MachineVerifier/test_g_incompatible_range.mir
index 14662a6b798827..5e8a089379cfa0 100644
--- a/llvm/test/MachineVerifier/test_g_incompatible_range.mir
+++ b/llvm/test/MachineVerifier/test_g_incompatible_range.mir
@@ -1,6 +1,6 @@
# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=none %s -filetype=null 2>&1 | FileCheck %s
--- |
- define void @range_metadata_sext_i33_signed_range_i64_load_as_v2i32() {
+ define void @mismatched_range_type() {
ret void
}
>From 80f6486bda67ffc90f14995c805445a6a88201f9 Mon Sep 17 00:00:00 2001
From: Renat Idrisov <4032256+parsifal-47 at users.noreply.github.com>
Date: Wed, 15 Jan 2025 07:06:23 -0800
Subject: [PATCH 10/11] Update
llvm/test/MachineVerifier/test_g_incompatible_range.mir
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
---
llvm/test/MachineVerifier/test_g_incompatible_range.mir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/MachineVerifier/test_g_incompatible_range.mir b/llvm/test/MachineVerifier/test_g_incompatible_range.mir
index 5e8a089379cfa0..a07e06fe4509ec 100644
--- a/llvm/test/MachineVerifier/test_g_incompatible_range.mir
+++ b/llvm/test/MachineVerifier/test_g_incompatible_range.mir
@@ -9,7 +9,7 @@
...
---
-name: range_metadata_sext_i33_signed_range_i64_load_as_v2i32
+name: mismatched_range_type
tracksRegLiveness: true
body: |
bb.0:
>From 314a0eb0e28e4e97f8a28538db4754dbd59012bc Mon Sep 17 00:00:00 2001
From: Renat Idrisov <4032256+parsifal-47 at users.noreply.github.com>
Date: Wed, 15 Jan 2025 07:06:46 -0800
Subject: [PATCH 11/11] Update llvm/lib/CodeGen/MachineVerifier.cpp
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
---
llvm/lib/CodeGen/MachineVerifier.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 54459a81deeb01..33a7decdad4723 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1280,7 +1280,7 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
mdconst::extract<ConstantInt>(MMO.getRanges()->getOperand(0));
if (i->getIntegerType()->getBitWidth() !=
ValTy.getScalarType().getSizeInBits()) {
- report("range is incompatible with the value it gets assigned to",
+ report("range is incompatible with the result type",
MI);
}
}
More information about the llvm-commits
mailing list