[llvm-bugs] [Bug 52135] New: [InstSimplify] fold compare of no-wrap subtract

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 11 05:51:36 PDT 2021


            Bug ID: 52135
           Summary: [InstSimplify] fold compare of no-wrap subtract
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org

Noticed in https://reviews.llvm.org/rGda210f5d3425 :

define i1 @test_negative_combined_sub_signed_overflow(i8 %x) {
  %y = sub nsw i8 127, %x
  %z = icmp slt i8 %y, -1
  ret i1 %z

This is always false.

define i1 @test_negative_combined_sub_unsigned_overflow(i64 %x) {
  %y = sub nuw i64 10, %x
  %z = icmp ult i64 %y, 11
  ret i1 %z

This is always true.


-instcombine will now handle those transforms in multiple steps, but it won't
work if the subtract has an extra use. 

This should be added to -instsimplify, so we don't have that limitation, and
the analysis can be used by other passes. 

The transforms should not be limited to "less-than" predicates. The check might
be implemented with a ConstantRange or an overflow check on constant math.

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/20211011/80871efd/attachment.html>

More information about the llvm-bugs mailing list