[llvm-bugs] [Bug 31512] New: missed simplification from llvm.assume

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 2 12:05:53 PST 2017


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

            Bug ID: 31512
           Summary: missed simplification 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

declare void @llvm.assume(i1)

define i8 @assume_guarantees_notnull(i8* %x) {
  %notnull = icmp ne i8* %x, null
  tail call void @llvm.assume(i1 %notnull)
  %ld = load i8, i8* %x
  %sel = select i1 %notnull, i8 %ld, i8 0
  ret i8 %sel
}

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

The assume should allow us to kill the select. Currently (trunk r290827), this
doesn't happen with -instsimplify or -newgvn, but it works with -gvn:

$ ./opt -gvn nullcheckload.ll -S -debug
Args: ./opt -gvn nullcheckload.ll -S -debug 
GVN iteration: 0
GVN: load i8 %ld has unknown dependence
GVN replacing:   %notnull = icmp ne i8* %x, null with i1 true in instruction  
%sel = select i1 %notnull, i8 %ld, i8 0
GVN removed:   %sel = select i1 true, i8 %ld, i8 0
GVN iteration: 1
GVN: load i8 %ld has unknown dependence
; ModuleID = 'nullcheckload.ll'
source_filename = "nullcheckload.ll"

; Function Attrs: nounwind
declare void @llvm.assume(i1) #0

define i8 @assume_guarantees_notnull(i8* %x) {
  %notnull = icmp ne i8* %x, null
  tail call void @llvm.assume(i1 %notnull)
  %ld = load i8, i8* %x
  ret i8 %ld
}

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

Is this a hole in instsimplify, newgvn, or both? 

I had assumed that simple folds like this belong in instsimplify. However, that
would require (?) a potentially expensive call to computeKnownBits (which calls
computeKnownBitsFromAssume), and there is concern about the compile-time cost
of value tracking.

Note that instsimplify works if the function argument is tagged with 'nonnull',
so that might be the preferred transform when possible? On the other hand, that
might be seen as abuse of parameter attributes.

define i8 @assume_guarantees_notnull2(i8* nonnull %x) {
  %notnull = icmp ne i8* %x, null
  %ld = load i8, i8* %x
  %sel = select i1 %notnull, i8 %ld, i8 0
  ret i8 %sel
}

$ ./opt -instsimplify nullcheckload.ll -S
define i8 @assume_guarantees_notnull2(i8* nonnull %x) {
  %ld = load i8, i8* %x
  ret i8 %ld
}

-- 
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/20170102/23bafbd4/attachment.html>


More information about the llvm-bugs mailing list