[llvm] r329360 - [InstCombine] add FP tests for Z - (X - Y); NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 15:56:54 PDT 2018


Author: spatel
Date: Thu Apr  5 15:56:54 2018
New Revision: 329360

URL: http://llvm.org/viewvc/llvm-project?rev=329360&view=rev
Log:
[InstCombine] add FP tests for Z - (X - Y); NFC

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.

Modified:
    llvm/trunk/test/Transforms/InstCombine/fsub.ll

Modified: llvm/trunk/test/Transforms/InstCombine/fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fsub.ll?rev=329360&r1=329359&r2=329360&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fsub.ll Thu Apr  5 15:56:54 2018
@@ -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) {




More information about the llvm-commits mailing list