[llvm] r367747 - [InstSimplify] Add test case to show bad sign bit handling for integer abs idiom in computeKnownBits.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 19:54:55 PDT 2019


Author: ctopper
Date: Fri Aug  2 19:54:54 2019
New Revision: 367747

URL: http://llvm.org/viewvc/llvm-project?rev=367747&view=rev
Log:
[InstSimplify] Add test case to show bad sign bit handling for integer abs idiom in computeKnownBits.

computeKnownBits will indicate the sign bit of abs is 0 if the
the RHS operand returned by matchSelectPattern has the nsw flag set.
For abs idioms like (X >= 0) ? X : -X, the RHS returns -X. But
we can also match ((X-Y) >= 0 ? X-Y : Y-X as abs. In this case
RHS will be the Y-X operand. According to Alive, the sign bit for
this is only 0 if both the X-Y and Y-X operands have the nsw flag.
But we're only checking the Y-X operand.

Modified:
    llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll

Modified: llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll?rev=367747&r1=367746&r2=367747&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll Fri Aug  2 19:54:54 2019
@@ -401,3 +401,15 @@ define i1 @nabs_no_intersection(i32 %a)
   ret i1 %r
 }
 
+; We can't fold this to false unless both subs have nsw.
+define i1 @abs_sub_sub_missing_nsw(i32 %x, i32 %y) {
+; CHECK-LABEL: @abs_sub_sub_missing_nsw(
+; CHECK-NEXT:    ret i1 false
+;
+  %a = sub i32 %x, %y
+  %b = sub nsw i32 %y, %x
+  %c = icmp sgt i32 %a, -1
+  %d = select i1 %c, i32 %a, i32 %b
+  %e = icmp slt i32 %d, 0
+  ret i1 %e
+}




More information about the llvm-commits mailing list