[llvm] ea096c9 - [SDAG] Remove noundef workaround for range metadata/attributes (#141745)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 01:56:52 PDT 2025
Author: Nikita Popov
Date: 2025-05-30T10:56:49+02:00
New Revision: ea096c98ae2c88ce9ba879be832caa8b254a348a
URL: https://github.com/llvm/llvm-project/commit/ea096c98ae2c88ce9ba879be832caa8b254a348a
DIFF: https://github.com/llvm/llvm-project/commit/ea096c98ae2c88ce9ba879be832caa8b254a348a.diff
LOG: [SDAG] Remove noundef workaround for range metadata/attributes (#141745)
In https://reviews.llvm.org/D157685 I changed SDAG to only transfer
range metadata to SDAG if it also has !noundef. At the time, this was
necessary because SDAG incorrectly propagated poison when folding
logical and/or to bitwise and/or.
The root cause of that issue has since been addressed by
https://github.com/llvm/llvm-project/pull/84924, so drop the workaround
now.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/test/CodeGen/AArch64/lower-range-metadata-func-call.ll
llvm/test/CodeGen/X86/pr37063.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 693a7f59629cb..77771ee56e828 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4468,23 +4468,13 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
}
static const MDNode *getRangeMetadata(const Instruction &I) {
- // If !noundef is not present, then !range violation results in a poison
- // value rather than immediate undefined behavior. In theory, transferring
- // these annotations to SDAG is fine, but in practice there are key SDAG
- // transforms that are known not to be poison-safe, such as folding logical
- // and/or to bitwise and/or. For now, only transfer !range if !noundef is
- // also present.
- if (!I.hasMetadata(LLVMContext::MD_noundef))
- return nullptr;
return I.getMetadata(LLVMContext::MD_range);
}
static std::optional<ConstantRange> getRange(const Instruction &I) {
- if (const auto *CB = dyn_cast<CallBase>(&I)) {
- // see comment in getRangeMetadata about this check
- if (CB->hasRetAttr(Attribute::NoUndef))
- return CB->getRange();
- }
+ if (const auto *CB = dyn_cast<CallBase>(&I))
+ if (std::optional<ConstantRange> CR = CB->getRange())
+ return CR;
if (const MDNode *Range = getRangeMetadata(I))
return getConstantRangeFromMetadata(*Range);
return std::nullopt;
diff --git a/llvm/test/CodeGen/AArch64/lower-range-metadata-func-call.ll b/llvm/test/CodeGen/AArch64/lower-range-metadata-func-call.ll
index 32f4df7fdba4b..eb190c486dc15 100644
--- a/llvm/test/CodeGen/AArch64/lower-range-metadata-func-call.ll
+++ b/llvm/test/CodeGen/AArch64/lower-range-metadata-func-call.ll
@@ -62,7 +62,6 @@ define i32 @test_call_known_max_range_attr_no_noundef() #0 {
; CHECK: // %bb.0: // %entry
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
; CHECK-NEXT: bl foo
-; CHECK-NEXT: and w0, w0, #0x3ff
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
; CHECK-NEXT: ret
entry:
diff --git a/llvm/test/CodeGen/X86/pr37063.ll b/llvm/test/CodeGen/X86/pr37063.ll
index 281da0c11f1f7..1d98ea921b748 100644
--- a/llvm/test/CodeGen/X86/pr37063.ll
+++ b/llvm/test/CodeGen/X86/pr37063.ll
@@ -7,7 +7,7 @@ define void @foo(ptr) {
; CHECK-LABEL: foo:
; CHECK: # %bb.0: # %start
; CHECK-NEXT: movl (%rdi), %eax
-; CHECK-NEXT: andl $6, %eax
+; CHECK-NEXT: andl $-2, %eax
; CHECK-NEXT: cmpl $4, %eax
; CHECK-NEXT: jne bar # TAILCALL
; CHECK-NEXT: # %bb.1: # %bb1
More information about the llvm-commits
mailing list