From 92a53eabc6deee78acce4b2e216aaffc4f71e00e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 5 Nov 2018 15:45:01 +0000 Subject: [InstCombine] add/adjust tests for select with fsub identity op; NFC llvm-svn: 346138 --- .../Transforms/InstCombine/select-binop-cmp.ll | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'llvm/test/Transforms') diff --git a/llvm/test/Transforms/InstCombine/select-binop-cmp.ll b/llvm/test/Transforms/InstCombine/select-binop-cmp.ll index edbe310269a..1604522293c 100644 --- a/llvm/test/Transforms/InstCombine/select-binop-cmp.ll +++ b/llvm/test/Transforms/InstCombine/select-binop-cmp.ll @@ -304,6 +304,21 @@ define float @select_fsub_fcmp(float %x, float %y, float %z) { 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(float %x, float %y, float %z) { 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 %x, float %y, float %z) { 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 } -- cgit v1.2.3