Skip to content

Commit 6017480

Browse files
authored
MachineVerifier: Fix check for range type (#124894)
We need to permit scalar extending loads with range annotations. Fix expensive_checks failures after 11db7fb
1 parent 97a1f49 commit 6017480

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,8 +1285,12 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
12851285
if (MMO.getRanges()) {
12861286
ConstantInt *i =
12871287
mdconst::extract<ConstantInt>(MMO.getRanges()->getOperand(0));
1288-
if (i->getIntegerType()->getBitWidth() !=
1289-
ValTy.getScalarType().getSizeInBits()) {
1288+
const LLT RangeTy = LLT::scalar(i->getIntegerType()->getBitWidth());
1289+
const LLT MemTy = MMO.getMemoryType();
1290+
if (MemTy.getScalarType() != RangeTy ||
1291+
ValTy.isScalar() != MemTy.isScalar() ||
1292+
(ValTy.isVector() &&
1293+
ValTy.getNumElements() != MemTy.getNumElements())) {
12901294
report("range is incompatible with the result type", MI);
12911295
}
12921296
}

llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-memory-metadata.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
!0 = !{i24 0, i24 1048575}
3131
!1 = !{!"omnipotent char", !2}
3232
!2 = !{!"Simple C/C++ TBAA"}
33-
!3 = !{i32 0, i32 1048575}
33+
!3 = !{i24 0, i24 1048575}
3434
...
3535

3636
# Make sure range metadata is not preserved when widening loads, but

llvm/test/MachineVerifier/AMDGPU/test_g_incompatible_range.mir

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: not --crash llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -run-pass=none -filetype=null %s 2>&1 | FileCheck %s
1+
# RUN: not --crash llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -run-pass=none -filetype=null %s 2>&1 | FileCheck -implicit-check-not="Bad machine code" %s
22
--- |
33
define void @mismatched_range_type() {
44
ret void
@@ -21,10 +21,18 @@ body: |
2121
; CHECK: Bad machine code: range is incompatible with the result type
2222
%3:_(<2 x s32>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
2323
24+
; CHECK: Bad machine code: range is incompatible with the result type
2425
%4:_(p0) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
2526
27+
; CHECK: Bad machine code: range is incompatible with the result type
2628
%5:_(<2 x p0>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
2729
30+
; CHECK: Bad machine code: range is incompatible with the result type
31+
%6:_(<3 x s64>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
32+
33+
; CHECK: Bad machine code: range is incompatible with the result type
34+
%7:_(<3 x s64>) = G_LOAD %0(p1) :: (volatile load (<2 x s64>), align 4, !range !0, addrspace 1)
35+
2836
$vgpr0_vgpr1 = COPY %3
2937
SI_RETURN implicit $vgpr0_vgpr1
3038

0 commit comments

Comments
 (0)