Skip to content

[SDAG] Remove noundef workaround for range metadata/attributes #141745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/pr37063.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading