Skip to content

In a function with a noundef return value, replace ret undef with unreachable #60717

Open
@scottmcm

Description

@scottmcm

noundef on the return value means that

If the value representation contains any undefined or poison bits, the behavior is undefined.

so if the function returns undef, that must be unreachable.

Alive2 confirms this is allowed: https://alive2.llvm.org/ce/z/bW2DoM

define i32 @src() noundef {
%start:
  ret i32 undef
}
=>
define i32 @tgt() noundef {
%start:
  assume i1 0
}
Transformation seems to be correct!

But seemingly it doesn't happen today: https://llvm.godbolt.org/z/79a91o59q

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions