[llvm-bugs] [Bug 31929] New: branch condition should be known from llvm.assume

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Feb 10 07:31:04 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31929

            Bug ID: 31929
           Summary: branch condition should be known from llvm.assume
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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 .

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170210/e9398a6e/attachment.html>


More information about the llvm-bugs mailing list