[llvm-bugs] [Bug 31596] New: deduce icmp result from llvm.assume

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 10 07:09:50 PST 2017


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

            Bug ID: 31596
           Summary: deduce icmp result from llvm.assume
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Transformation Utilities
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Filing this based on a question from Daniel Berlin:
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170109/418024.html

declare void @llvm.assume(i1)

define i1 @deduce_icmp_from_assume(i8 %a, i8 %b) {
  %eqcond = icmp eq i8 %a, %b
  call void @llvm.assume(i1 %eqcond)
  %ltcond = icmp slt i8 %a, %b
  ret i1 %ltcond
}

------------------------------------------------------------------------------

Some pass (don't know which one yet because the line between analysis and the
compile-time cost of that analysis is not clear) should be able to simplify
this to return 'false', but nothing in the -O2 pipeline as of r291443 handles
this.

FWIW, we already call computeKnownBits in InstCombiner::visitReturnInst() for
the stated purpose of checking assumptions:
  // There might be assume intrinsics dominating this return that completely
  // determine the value. If so, constant fold it.

...so this particular case could be handled by adding to the pattern-matching
logic in computeKnownBitsFromAssume() ( see https://reviews.llvm.org/D28485 ),
but of course that's not the most general solution. 

More typically, we'd expect the 2nd icmp result to be used in a branch or
select, so calling value tracking (should computeKnownBitsFromAssume be raised
into the value tracking API?) when visiting those insts in InstCombine might be
a better way. I have a patch proposal for the select variant here:
https://reviews.llvm.org/D28337

There may be no good solution because the design of the llvm.assume intrinsic
itself just isn't ideal ( bug 31518, comment 10 ). Alternative suggestions are
that we should convert it to a form more like llvm.expect:
bug 31512, comment 4

That could lead to a lower-to-metadata pass such as "-lower-expect", so we
wouldn't have the problem of optimization intrinsics interfering with
optimization as noted by Eli here:
https://reviews.llvm.org/D27114

-- 
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/20170110/7ccf947f/attachment.html>


More information about the llvm-bugs mailing list