[llvm-bugs] [Bug 43172] New: Example of missing overflow check folds

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 29 15:43:49 PDT 2019


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

            Bug ID: 43172
           Summary: Example of missing overflow check folds
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: listmail at philipreames.com
                CC: llvm-bugs at lists.llvm.org

Here is a collection of overflow check idioms which we don't currently turn
into the op.with.overflow equivalents (or more importantly, generate op
w/following OF flag check on x86).  

add i32, i32
  %8 = add i32 %1, %0                                                           
  %9 = xor i32 %8, %0                                                           
  %10 = xor i32 %8, %1                                                          
  %11 = and i32 %9, %10                                                         
  %12 = icmp sgt i32 %11, -1                                                    

sub i32 i32
  %8 = sub i32 %0, %1                                                           
  %9 = xor i32 %1, %0                                                           
  %10 = xor i32 %8, %0                                                          
  %11 = and i32 %10, %9                                                         
  %12 = icmp sgt i32 %11, -1

mul i32 i32
  %8 = sext i32 %0 to i64                                                       
  %9 = sext i32 %1 to i64                                                       
  %10 = mul nsw i64 %9, %8                                                      
  %11 = add nsw i64 %10, 2147483648                                             
  %12 = icmp ult i64 %11, 4294967296

increment i32 (i.e. add i32 1)
  %7 = icmp eq i32 %0, 2147483647 
  ...                                                                           
  %9 = add nsw i32 %0, 1                                                        
  ret i32 %9 

Note that in all cases, there's a branch on the overflow check leading to an
exception block.  I left that out for simplicity. 

All of these are derived from
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/java/lang/Math.java
opExact family of methods.

-- 
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/20190829/b7fab663/attachment.html>


More information about the llvm-bugs mailing list