[llvm] r346138 - [InstCombine] add/adjust tests for select with fsub identity op; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 5 07:45:02 PST 2018


Author: spatel
Date: Mon Nov  5 07:45:01 2018
New Revision: 346138

URL: http://llvm.org/viewvc/llvm-project?rev=346138&view=rev
Log:
[InstCombine] add/adjust tests for select with fsub identity op; NFC

Modified:
    llvm/trunk/test/Transforms/InstCombine/select-binop-cmp.ll

Modified: llvm/trunk/test/Transforms/InstCombine/select-binop-cmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select-binop-cmp.ll?rev=346138&r1=346137&r2=346138&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/select-binop-cmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/select-binop-cmp.ll Mon Nov  5 07:45:01 2018
@@ -304,6 +304,21 @@ define float @select_fsub_fcmp(float %x,
   ret float %C
 }
 
+; TODO: This is logically equivalent to the previous test - fcmp ignores the sign of 0.0.
+
+define float @select_fsub_fcmp_negzero(float %x, float %y, float %z) {
+; CHECK-LABEL: @select_fsub_fcmp_negzero(
+; CHECK-NEXT:    [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
+; CHECK-NEXT:    [[B:%.*]] = fsub nsz float [[Z:%.*]], [[X]]
+; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
+; CHECK-NEXT:    ret float [[C]]
+;
+  %A = fcmp oeq float %x, -0.0
+  %B = fsub nsz float %z, %x
+  %C = select i1 %A, float %B, float %y
+  ret float %C
+}
+
 define float @select_fdiv_fcmp(float %x, float %y, float %z) {
 ; CHECK-LABEL: @select_fdiv_fcmp(
 ; CHECK-NEXT:    [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
@@ -899,15 +914,18 @@ define float @select_fdiv_fcmp_bad_2(flo
   ret float %C
 }
 
+; The transform is not valid when x = -0.0 and z = -0.0 
+; (optimized code would return -0.0, but this returns +0.0). 
+
 define float @select_fsub_fcmp_bad(float %x, float %y, float %z) {
 ; CHECK-LABEL: @select_fsub_fcmp_bad(
 ; CHECK-NEXT:    [[A:%.*]] = fcmp oeq float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT:    [[B:%.*]] = fsub float [[X]], [[Z:%.*]]
+; CHECK-NEXT:    [[B:%.*]] = fsub float [[Z:%.*]], [[X]]
 ; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
 ; CHECK-NEXT:    ret float [[C]]
 ;
   %A = fcmp oeq float %x, 0.0
-  %B = fsub float %x, %z
+  %B = fsub float %z, %x
   %C = select i1 %A, float %B, float %y
   ret float %C
 }
@@ -915,12 +933,12 @@ define float @select_fsub_fcmp_bad(float
 define float @select_fsub_fcmp_bad_2(float %x, float %y, float %z) {
 ; CHECK-LABEL: @select_fsub_fcmp_bad_2(
 ; CHECK-NEXT:    [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[B:%.*]] = fsub nsz float [[X]], [[Z:%.*]]
+; CHECK-NEXT:    [[B:%.*]] = fsub nsz float [[Z:%.*]], [[X]]
 ; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
 ; CHECK-NEXT:    ret float [[C]]
 ;
   %A = fcmp oeq float %x, 1.0
-  %B = fsub nsz float %x, %z
+  %B = fsub nsz float %z, %x
   %C = select i1 %A, float %B, float %y
   ret float %C
 }




More information about the llvm-commits mailing list