Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/lib/CodeGen/MachineVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,15 @@ 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()) {
ConstantInt *i =
mdconst::extract<ConstantInt>(MMO.getRanges()->getOperand(0));
if (i->getIntegerType()->getBitWidth() !=
MMO.getMemoryType().getScalarSizeInBits()) {
report("range is incompatible with the result type", MI);
}
}
} else if (MI->getOpcode() == TargetOpcode::G_STORE) {
if (TypeSize::isKnownLT(ValTy.getSizeInBytes(),
MMO.getSize().getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
!0 = !{i96 0, i96 9223372036854775808}
!1 = !{!"omnipotent char", !2}
!2 = !{!"Simple C/C++ TBAA"}
!3 = !{i32 0, i32 2147483646}
...

# Make sure range metadata is not preserved when widening loads, but
Expand Down Expand Up @@ -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

...
Expand Down
33 changes: 33 additions & 0 deletions llvm/test/MachineVerifier/test_g_incompatible_range.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# RUN: not --crash llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=none %s -filetype=null 2>&1 | FileCheck %s
--- |
define void @mismatched_range_type() {
ret void
}

!0 = !{i64 -4294967295, i64 4294967296}

...
---
name: mismatched_range_type
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)

; CHECK: Bad machine code: range is incompatible with the value it gets assigned to
%4:_(p0) = 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 p0>) = G_LOAD %0(p1) :: (volatile load (s64), align 4, !range !0, addrspace 1)

$vgpr0_vgpr1 = COPY %3
SI_RETURN implicit $vgpr0_vgpr1

...
Loading