Skip to content

Commit

Permalink
MachineVerifier: Fix check for range type (llvm#124894)
Browse files Browse the repository at this point in the history
We need to permit scalar extending loads with range annotations.

Fix expensive_checks failures after 11db7fb
  • Loading branch information
arsenm authored Jan 30, 2025
1 parent 97a1f49 commit 6017480
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions llvm/lib/CodeGen/MachineVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,12 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
if (MMO.getRanges()) {
ConstantInt *i =
mdconst::extract<ConstantInt>(MMO.getRanges()->getOperand(0));
if (i->getIntegerType()->getBitWidth() !=
ValTy.getScalarType().getSizeInBits()) {
const LLT RangeTy = LLT::scalar(i->getIntegerType()->getBitWidth());
const LLT MemTy = MMO.getMemoryType();
if (MemTy.getScalarType() != RangeTy ||
ValTy.isScalar() != MemTy.isScalar() ||
(ValTy.isVector() &&
ValTy.getNumElements() != MemTy.getNumElements())) {
report("range is incompatible with the result type", MI);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
!0 = !{i24 0, i24 1048575}
!1 = !{!"omnipotent char", !2}
!2 = !{!"Simple C/C++ TBAA"}
!3 = !{i32 0, i32 1048575}
!3 = !{i24 0, i24 1048575}
...

# Make sure range metadata is not preserved when widening loads, but
Expand Down
10 changes: 9 additions & 1 deletion llvm/test/MachineVerifier/AMDGPU/test_g_incompatible_range.mir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RUN: not --crash llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -run-pass=none -filetype=null %s 2>&1 | FileCheck %s
# 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
--- |
define void @mismatched_range_type() {
ret void
Expand All @@ -21,10 +21,18 @@ body: |
; CHECK: Bad machine code: range is incompatible with the result type
%3:_(<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 result type
%4:_(p0) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
; CHECK: Bad machine code: range is incompatible with the result type
%5:_(<2 x p0>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
; CHECK: Bad machine code: range is incompatible with the result type
%6:_(<3 x s64>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)
; CHECK: Bad machine code: range is incompatible with the result type
%7:_(<3 x s64>) = G_LOAD %0(p1) :: (volatile load (<2 x s64>), align 4, !range !0, addrspace 1)
$vgpr0_vgpr1 = COPY %3
SI_RETURN implicit $vgpr0_vgpr1
Expand Down

0 comments on commit 6017480

Please sign in to comment.