D141386 changed the semantics of !range metadata to return poison
on violation. If !range is combined with !noundef, violation is
immediate UB instead, matching the old semantics.
In theory, these IR semantics should also carry over into SDAG.
In practice, DAGCombine has at least one key transform that is
invalid in the presence of poison, namely the conversion of logical
and/or to bitwise and/or (c7b537bf09/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (L11252)).
Ideally, we would fix this transform, but this will require
substantial work to avoid codegen regressions.
In the meantime, avoid transferring !range metadata without
!noundef, effectively restoring the old !range metadata semantics
on the SDAG layer.
Fixes https://github.com/llvm/llvm-project/issues/64589.
Differential Revision: https://reviews.llvm.org/D157685
150 lines
5.5 KiB
LLVM
150 lines
5.5 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN %s
|
|
|
|
define i32 @range_metadata_sext_i8_signed_range_i32(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_i8_signed_range_i32:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dword v0, v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i32, ptr addrspace(1) %ptr, align 4, !range !0, !noundef !{} ; [-127, 128)
|
|
%shl = shl i32 %val, 24
|
|
%ashr = ashr i32 %shl, 24
|
|
ret i32 %ashr
|
|
}
|
|
|
|
define i32 @range_metadata_sext_upper_range_limited_i32(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_upper_range_limited_i32:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dword v0, v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: v_bfe_i32 v0, v0, 0, 8
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i32, ptr addrspace(1) %ptr, align 4, !range !1, !noundef !{} ; [-127, 256)
|
|
%shl = shl i32 %val, 24
|
|
%ashr = ashr i32 %shl, 24
|
|
ret i32 %ashr
|
|
}
|
|
|
|
define i32 @range_metadata_sext_lower_range_limited_i32(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_lower_range_limited_i32:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dword v0, v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: v_bfe_i32 v0, v0, 0, 8
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i32, ptr addrspace(1) %ptr, align 4, !range !2 ; [-255, 128)
|
|
%shl = shl i32 %val, 24
|
|
%ashr = ashr i32 %shl, 24
|
|
ret i32 %ashr
|
|
}
|
|
|
|
define i32 @range_metadata_sext_i8_neg_neg_range_i32(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_i8_neg_neg_range_i32:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dword v0, v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: v_and_b32_e32 v0, 63, v0
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i32, ptr addrspace(1) %ptr, align 4, !range !3, !noundef !{}
|
|
%shl = shl i32 %val, 25
|
|
%ashr = ashr i32 %shl, 25
|
|
ret i32 %ashr
|
|
}
|
|
|
|
define i32 @range_metadata_sextload_i8_signed_range_i4_i32(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sextload_i8_signed_range_i4_i32:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_sbyte v0, v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%load = load volatile i8, ptr addrspace(1) %ptr, align 1, !range !4, !noundef !{}
|
|
%shl = shl i8 %load, 3
|
|
%ashr = ashr i8 %shl, 3
|
|
%ext = sext i8 %ashr to i32
|
|
ret i32 %ext
|
|
}
|
|
|
|
define i25 @range_metadata_sext_i8_signed_range_i25(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_i8_signed_range_i25:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dword v0, v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: v_bfe_i32 v0, v0, 0, 2
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i25, ptr addrspace(1) %ptr, align 4, !range !5, !noundef !{}
|
|
%shl = shl i25 %val, 23
|
|
%ashr = ashr i25 %shl, 23
|
|
ret i25 %ashr
|
|
}
|
|
|
|
define i32 @range_metadata_i32_neg1_to_1(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_i32_neg1_to_1:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dword v0, v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i32, ptr addrspace(1) %ptr, align 4, !range !6, !noundef !{}
|
|
%shl = shl i32 %val, 31
|
|
%ashr = ashr i32 %shl, 31
|
|
ret i32 %ashr
|
|
}
|
|
|
|
define i64 @range_metadata_sext_i8_signed_range_i64(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_i8_signed_range_i64:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dwordx2 v[0:1], v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: v_lshlrev_b32_e32 v1, 23, v0
|
|
; GCN-NEXT: v_ashrrev_i64 v[0:1], 55, v[0:1]
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i64, ptr addrspace(1) %ptr, align 4, !range !7, !noundef !{}
|
|
%shl = shl i64 %val, 55
|
|
%ashr = ashr i64 %shl, 55
|
|
ret i64 %ashr
|
|
}
|
|
|
|
define i64 @range_metadata_sext_i32_signed_range_i64(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_i32_signed_range_i64:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dwordx2 v[0:1], v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i64, ptr addrspace(1) %ptr, align 4, !range !7, !noundef !{}
|
|
%shl = shl i64 %val, 31
|
|
%ashr = ashr i64 %shl, 31
|
|
ret i64 %ashr
|
|
}
|
|
|
|
define i64 @range_metadata_sext_i33_signed_range_i64(ptr addrspace(1) %ptr) {
|
|
; GCN-LABEL: range_metadata_sext_i33_signed_range_i64:
|
|
; GCN: ; %bb.0:
|
|
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
|
|
; GCN-NEXT: global_load_dwordx2 v[0:1], v[0:1], off glc
|
|
; GCN-NEXT: s_waitcnt vmcnt(0)
|
|
; GCN-NEXT: s_setpc_b64 s[30:31]
|
|
%val = load volatile i64, ptr addrspace(1) %ptr, align 4, !range !8, !noundef !{}
|
|
%shl = shl i64 %val, 30
|
|
%ashr = ashr i64 %shl, 30
|
|
ret i64 %ashr
|
|
}
|
|
|
|
!0 = !{i32 -127, i32 128}
|
|
!1 = !{i32 -127, i32 256}
|
|
!2 = !{i32 -255, i32 128}
|
|
!3 = !{i32 -127, i32 -64}
|
|
!4 = !{i8 -15, i8 16}
|
|
!5 = !{i25 -127, i25 128}
|
|
!6 = !{i32 -1, i32 1}
|
|
!7 = !{i64 -4294967295, i64 4294967296}
|
|
!8 = !{i64 -8589934591, i64 8589934592}
|