Skip to content

[DAG] SelectionDAG::canCreateUndefOrPoison - when can we bypass poison generating flags?Β #155439

@RKSimon

Description

@RKSimon

Currently if a node has any poison generating flags canCreateUndefOrPoison always returns true:

https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L5638-L5642

However, if we can easily prove the flag, e.g. nuw - when are we allowed to use valuetracking to perform a better analysis of the node?

e.g.

define i8 @src(i4 %a0, i4 %a1) {
  %x0 = zext i4 %a0 to i8
  %x1 = zext i4 %a1 to i8
  %add = add nuw i8 %x0, %x1 ; zext proves nuw so should be safe to push freeze through to operands?
  %res = freeze i8 %add
  ret i8 %res
}

define i8 @tgt(i4 %a0, i4 %a1) {
  %f0 = freeze i4 %a0
  %f1 = freeze i4 %a1
  %x0 = zext i4 %f0 to i8
  %x1 = zext i4 %f1 to i8
  %add = add nuw i8 %x0, %x1
  ret i8 %add
}
Transformation seems to be correct!

CC @nikic @dtcxzyw @nunoplopes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions