Skip to content

branch condition should be known from llvm.assume #31277

@rotateright

Description

@rotateright
Bugzilla Link 31929
Version trunk
OS All
CC @hfinkel

Extended Description

Filing this based on the request in:
https://reviews.llvm.org/D28204

These are purposely minimized to be instcombine tests. If we decide that the functionality doesn't belong there, then the tests may require additional instructions to thwart other transformations (phi -> select) and/or trigger from a different pass (LICM?).


declare void @llvm.assume(i1)

define i8 @assume_guarantees_notnull(i8* %x) {
entry:
  %notnull = icmp ne i8* %x, null
  tail call void @llvm.assume(i1 %notnull)
  br i1 %notnull, label %if, label %endif   <--- condition is known true
if:
  %ld = load i8, i8* %x
  br label %endif
endif:
  %sel = phi i8 [ 0, %entry ], [ %ld, %if ]
  ret i8 %sel
}

Depending on how we want to solve this, it may be relevant to use a non-pointer value in the icmp:

define i8 @​assume_guarantees_notnull(i8 %y, i8* %x) {
entry:
%notnull = icmp ne i8 %y, 0 <--- type shouldn't matter?
tail call void @​llvm.assume(i1 %notnull)
br i1 %notnull, label %if, label %endif
if:
%ld = load i8, i8* %x, align 1
br label %endif
endif:
%sel = phi i8 [ 0, %entry ], [ %ld, %if ]
ret i8 %sel
}


For reference, we handle the 'select' variant of these examples in instcombine by calling computeKnownBits when we know there might be an assumption that defines the condition. That was bug 31512 / https://reviews.llvm.org/rL291915 .

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions