From 715ba6531757530a0d51b9a1793fdd2d02b5713c Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 5 Apr 2018 22:56:54 +0000 Subject: [PATCH] [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. llvm-svn: 329360 --- llvm/test/Transforms/InstCombine/fsub.ll | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/fsub.ll b/llvm/test/Transforms/InstCombine/fsub.ll index 3fbafc2..184d24f 100644 --- a/llvm/test/Transforms/InstCombine/fsub.ll +++ b/llvm/test/Transforms/InstCombine/fsub.ll @@ -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 +} + ; define double @test2(double %x, double %y) { -- 2.7.4