[InstCombine] add FP tests for Z - (X - Y); NFC
authorSanjay Patel <spatel@rotateright.com>
Thu, 5 Apr 2018 22:56:54 +0000 (22:56 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 5 Apr 2018 22:56:54 +0000 (22:56 +0000)
A fold for this pattern was removed at rL73243 to fix PR4374:
https://bugs.llvm.org/show_bug.cgi?id=4374
...and apparently there were no tests that went with that fold.

llvm-svn: 329360

llvm/test/Transforms/InstCombine/fsub.ll

index 3fbafc2..184d24f 100644 (file)
@@ -14,11 +14,11 @@ define float @test1(float %x, float %y) {
   ret float %t2
 }
 
-; FIXME: Can't do anything with the test above because -0.0 - 0.0 = -0.0, but if we have nsz:
+; Can't do anything with the test above because -0.0 - 0.0 = -0.0, but if we have nsz:
 ; -(X - Y) --> Y - X
 
-define float @neg_sub(float %x, float %y) {
-; CHECK-LABEL: @neg_sub(
+define float @neg_sub_nsz(float %x, float %y) {
+; CHECK-LABEL: @neg_sub_nsz(
 ; CHECK-NEXT:    [[T2:%.*]] = fsub nsz float [[Y:%.*]], [[X:%.*]]
 ; CHECK-NEXT:    ret float [[T2]]
 ;
@@ -27,6 +27,32 @@ define float @neg_sub(float %x, float %y) {
   ret float %t2
 }
 
+; FIXME: With nsz: Z - (X - Y) --> Z + (Y - X)
+
+define float @sub_sub_nsz(float %x, float %y, float %z) {
+; CHECK-LABEL: @sub_sub_nsz(
+; CHECK-NEXT:    [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = fsub nsz float [[Z:%.*]], [[T1]]
+; CHECK-NEXT:    ret float [[T2]]
+;
+  %t1 = fsub float %x, %y
+  %t2 = fsub nsz float %z, %t1
+  ret float %t2
+}
+
+; FIXME: Same as above: if 'Z' is not -0.0, swap fsub operands and convert to fadd.
+
+define float @sub_sub_known_not_negzero(float %x, float %y) {
+; CHECK-LABEL: @sub_sub_known_not_negzero(
+; CHECK-NEXT:    [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = fsub float 4.200000e+01, [[T1]]
+; CHECK-NEXT:    ret float [[T2]]
+;
+  %t1 = fsub float %x, %y
+  %t2 = fsub float 42.0, %t1
+  ret float %t2
+}
+
 ; <rdar://problem/7530098>
 
 define double @test2(double %x, double %y) {