[SDAG] Don't transfer !range metadata without !noundef to SDAG (PR64589)
authorNikita Popov <npopov@redhat.com>
Fri, 11 Aug 2023 08:06:35 +0000 (10:06 +0200)
committerTobias Hieta <tobias@hieta.se>
Tue, 15 Aug 2023 09:07:53 +0000 (11:07 +0200)
commitf1249072f39e539386572ce46a76743c58b00608
tree5fcede010d8ec9c0d16621b04ebcad63e9ca0056
parent9b202cad8905c54e5da394b4739a0df5bc7eb3ae
[SDAG] Don't transfer !range metadata without !noundef to SDAG (PR64589)

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 (https://github.com/llvm/llvm-project/blob/c7b537bf0923df05254f9fa4722b298eb8f4790d/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

(cherry picked from commit 9deee6bffa9c331f46c68e5dd4cb4abf93dc0716)
14 files changed:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
llvm/test/CodeGen/AArch64/lower-range-metadata-func-call.ll
llvm/test/CodeGen/AMDGPU/array-ptr-calc-i32.ll
llvm/test/CodeGen/AMDGPU/global-saddr-load.ll
llvm/test/CodeGen/AMDGPU/load-range-metadata-assert.ll
llvm/test/CodeGen/AMDGPU/load-range-metadata-sign-bits.ll
llvm/test/CodeGen/PowerPC/BreakableToken-reduced.ll
llvm/test/CodeGen/PowerPC/global-address-non-got-indirect-access.ll
llvm/test/CodeGen/X86/legalize-vec-assertzext.ll
llvm/test/CodeGen/X86/pr12360.ll
llvm/test/CodeGen/X86/pr48458.ll
llvm/test/CodeGen/X86/pr48888.ll
llvm/test/CodeGen/X86/pr64589.ll