Skip to content

Commit d857e74

Browse files
committed
MachineVerifier: Fix check for range type
We need to permit scalar extending loads with range annotations. Fix expensive_checks failures after 11db7fb
1 parent a01097f commit d857e74

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
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/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)