Skip to content

Commit ea096c9

Browse files
authored
[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 #84924, so drop the workaround now.
1 parent 5483190 commit ea096c9

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,23 +4468,13 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
44684468
}
44694469

44704470
static const MDNode *getRangeMetadata(const Instruction &I) {
4471-
// If !noundef is not present, then !range violation results in a poison
4472-
// value rather than immediate undefined behavior. In theory, transferring
4473-
// these annotations to SDAG is fine, but in practice there are key SDAG
4474-
// transforms that are known not to be poison-safe, such as folding logical
4475-
// and/or to bitwise and/or. For now, only transfer !range if !noundef is
4476-
// also present.
4477-
if (!I.hasMetadata(LLVMContext::MD_noundef))
4478-
return nullptr;
44794471
return I.getMetadata(LLVMContext::MD_range);
44804472
}
44814473

44824474
static std::optional<ConstantRange> getRange(const Instruction &I) {
4483-
if (const auto *CB = dyn_cast<CallBase>(&I)) {
4484-
// see comment in getRangeMetadata about this check
4485-
if (CB->hasRetAttr(Attribute::NoUndef))
4486-
return CB->getRange();
4487-
}
4475+
if (const auto *CB = dyn_cast<CallBase>(&I))
4476+
if (std::optional<ConstantRange> CR = CB->getRange())
4477+
return CR;
44884478
if (const MDNode *Range = getRangeMetadata(I))
44894479
return getConstantRangeFromMetadata(*Range);
44904480
return std::nullopt;

llvm/test/CodeGen/AArch64/lower-range-metadata-func-call.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ define i32 @test_call_known_max_range_attr_no_noundef() #0 {
6262
; CHECK: // %bb.0: // %entry
6363
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
6464
; CHECK-NEXT: bl foo
65-
; CHECK-NEXT: and w0, w0, #0x3ff
6665
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
6766
; CHECK-NEXT: ret
6867
entry:

llvm/test/CodeGen/X86/pr37063.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ define void @foo(ptr) {
77
; CHECK-LABEL: foo:
88
; CHECK: # %bb.0: # %start
99
; CHECK-NEXT: movl (%rdi), %eax
10-
; CHECK-NEXT: andl $6, %eax
10+
; CHECK-NEXT: andl $-2, %eax
1111
; CHECK-NEXT: cmpl $4, %eax
1212
; CHECK-NEXT: jne bar # TAILCALL
1313
; CHECK-NEXT: # %bb.1: # %bb1

0 commit comments

Comments
 (0)