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
26 lines
859 B
LLVM
26 lines
859 B
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
|
|
; RUN: llc -mtriple=x86_64-- < %s | FileCheck %s
|
|
|
|
; It's not possible to directly or the two loads together, because this might
|
|
; propagate a poison value from the second load (which has !range but not
|
|
; !noundef).
|
|
define i8 @test(ptr %p) {
|
|
; CHECK-LABEL: test:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: movzbl (%rdi), %eax
|
|
; CHECK-NEXT: orb 1(%rdi), %al
|
|
; CHECK-NEXT: setne %al
|
|
; CHECK-NEXT: addb %al, %al
|
|
; CHECK-NEXT: retq
|
|
%v1 = load i8, ptr %p, align 4, !range !0, !noundef !{}
|
|
%cmp1 = icmp ne i8 %v1, 0
|
|
%p2 = getelementptr inbounds i8, ptr %p, i64 1
|
|
%v2 = load i8, ptr %p2, align 1, !range !0
|
|
%cmp2 = icmp ne i8 %v2, 0
|
|
%or = select i1 %cmp1, i1 true, i1 %cmp2
|
|
%res = select i1 %or, i8 2, i8 0
|
|
ret i8 %res
|
|
}
|
|
|
|
!0 = !{i8 0, i8 2}
|