[llvm] r361971 - [NFC][InstCombine] Add unary FNeg tests to fsub.ll known-never-nan.ll

Cameron McInally via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 08:21:28 PDT 2019


Author: mcinally
Date: Wed May 29 08:21:28 2019
New Revision: 361971

URL: http://llvm.org/viewvc/llvm-project?rev=361971&view=rev
Log:
[NFC][InstCombine] Add unary FNeg tests to fsub.ll known-never-nan.ll

Modified:
    llvm/trunk/test/Transforms/InstCombine/fsub.ll
    llvm/trunk/test/Transforms/InstCombine/known-never-nan.ll

Modified: llvm/trunk/test/Transforms/InstCombine/fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fsub.ll?rev=361971&r1=361970&r2=361971&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fsub.ll Wed May 29 08:21:28 2019
@@ -27,6 +27,18 @@ define float @neg_sub_nsz(float %x, floa
   ret float %t2
 }
 
+; FIXME: This combine isn't working.
+define float @unary_neg_sub_nsz(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_sub_nsz(
+; CHECK-NEXT:    [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = fneg nsz float [[T1]]
+; CHECK-NEXT:    ret float [[T2]]
+;
+  %t1 = fsub float %x, %y
+  %t2 = fneg nsz float %t1
+  ret float %t2
+}
+
 ; If the subtract has another use, we don't do the transform (even though it
 ; doesn't increase the IR instruction count) because we assume that fneg is
 ; easier to analyze and generally cheaper than generic fsub.
@@ -47,6 +59,19 @@ define float @neg_sub_nsz_extra_use(floa
   ret float %t2
 }
 
+define float @unary_neg_sub_nsz_extra_use(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_sub_nsz_extra_use(
+; CHECK-NEXT:    [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = fneg nsz float [[T1]]
+; CHECK-NEXT:    call void @use(float [[T1]])
+; CHECK-NEXT:    ret float [[T2]]
+;
+  %t1 = fsub float %x, %y
+  %t2 = fneg nsz float %t1
+  call void @use(float %t1)
+  ret float %t2
+}
+
 ; With nsz: Z - (X - Y) --> Z + (Y - X)
 
 define float @sub_sub_nsz(float %x, float %y, float %z) {
@@ -140,6 +165,16 @@ define float @neg_op1(float %x, float %y
   ret float %r
 }
 
+define float @unary_neg_op1(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_op1(
+; CHECK-NEXT:    [[R:%.*]] = fadd float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    ret float [[R]]
+;
+  %negy = fneg float %y
+  %r = fsub float %x, %negy
+  ret float %r
+}
+
 define <2 x float> @neg_op1_vec(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @neg_op1_vec(
 ; CHECK-NEXT:    [[R:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
@@ -150,6 +185,16 @@ define <2 x float> @neg_op1_vec(<2 x flo
   ret <2 x float> %r
 }
 
+define <2 x float> @unary_neg_op1_vec(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @unary_neg_op1_vec(
+; CHECK-NEXT:    [[R:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    ret <2 x float> [[R]]
+;
+  %negy = fneg <2 x float> %y
+  %r = fsub <2 x float> %x, %negy
+  ret <2 x float> %r
+}
+
 define <2 x float> @neg_op1_vec_undef(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @neg_op1_vec_undef(
 ; CHECK-NEXT:    [[R:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
@@ -174,6 +219,18 @@ define double @neg_ext_op1(float %a, dou
   ret double %t3
 }
 
+define double @unary_neg_ext_op1(float %a, double %b) {
+; CHECK-LABEL: @unary_neg_ext_op1(
+; CHECK-NEXT:    [[TMP1:%.*]] = fpext float [[A:%.*]] to double
+; CHECK-NEXT:    [[T3:%.*]] = fadd double [[TMP1]], [[B:%.*]]
+; CHECK-NEXT:    ret double [[T3]]
+;
+  %t1 = fneg float %a
+  %t2 = fpext float %t1 to double
+  %t3 = fsub double %b, %t2
+  ret double %t3
+}
+
 ; Verify that vectors work too.
 
 define <2 x float> @neg_trunc_op1(<2 x double> %a, <2 x float> %b) {
@@ -188,6 +245,18 @@ define <2 x float> @neg_trunc_op1(<2 x d
   ret <2 x float> %t3
 }
 
+define <2 x float> @unary_neg_trunc_op1(<2 x double> %a, <2 x float> %b) {
+; CHECK-LABEL: @unary_neg_trunc_op1(
+; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc <2 x double> [[A:%.*]] to <2 x float>
+; CHECK-NEXT:    [[T3:%.*]] = fadd <2 x float> [[TMP1]], [[B:%.*]]
+; CHECK-NEXT:    ret <2 x float> [[T3]]
+;
+  %t1 = fneg <2 x double> %a
+  %t2 = fptrunc <2 x double> %t1 to <2 x float>
+  %t3 = fsub <2 x float> %b, %t2
+  ret <2 x float> %t3
+}
+
 ; No FMF needed, but they should propagate to the fadd.
 
 define double @neg_ext_op1_fast(float %a, double %b) {
@@ -202,6 +271,18 @@ define double @neg_ext_op1_fast(float %a
   ret double %t3
 }
 
+define double @unary_neg_ext_op1_fast(float %a, double %b) {
+; CHECK-LABEL: @unary_neg_ext_op1_fast(
+; CHECK-NEXT:    [[TMP1:%.*]] = fpext float [[A:%.*]] to double
+; CHECK-NEXT:    [[T3:%.*]] = fadd fast double [[TMP1]], [[B:%.*]]
+; CHECK-NEXT:    ret double [[T3]]
+;
+  %t1 = fneg float %a
+  %t2 = fpext float %t1 to double
+  %t3 = fsub fast double %b, %t2
+  ret double %t3
+}
+
 ; Extra use should prevent the transform.
 
 define float @neg_ext_op1_extra_use(half %a, float %b) {
@@ -219,6 +300,21 @@ define float @neg_ext_op1_extra_use(half
   ret float %t3
 }
 
+define float @unary_neg_ext_op1_extra_use(half %a, float %b) {
+; CHECK-LABEL: @unary_neg_ext_op1_extra_use(
+; CHECK-NEXT:    [[T1:%.*]] = fneg half [[A:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = fpext half [[T1]] to float
+; CHECK-NEXT:    [[T3:%.*]] = fsub float [[B:%.*]], [[T2]]
+; CHECK-NEXT:    call void @use(float [[T2]])
+; CHECK-NEXT:    ret float [[T3]]
+;
+  %t1 = fneg half %a
+  %t2 = fpext half %t1 to float
+  %t3 = fsub float %b, %t2
+  call void @use(float %t2)
+  ret float %t3
+}
+
 ; One-use fptrunc is always hoisted above fneg, so the corresponding
 ; multi-use bug for fptrunc isn't visible with a fold starting from
 ; the last fsub.
@@ -238,6 +334,22 @@ define float @neg_trunc_op1_extra_use(do
   ret float %t3
 }
 
+; FIXME: This combine isn't working.
+define float @unary_neg_trunc_op1_extra_use(double %a, float %b) {
+; CHECK-LABEL: @unary_neg_trunc_op1_extra_use(
+; CHECK-NEXT:    [[T1:%.*]] = fneg double [[A:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = fptrunc double [[T1]] to float
+; CHECK-NEXT:    [[T3:%.*]] = fsub float [[B:%.*]], [[T2]]
+; CHECK-NEXT:    call void @use(float [[T2]])
+; CHECK-NEXT:    ret float [[T3]]
+;
+  %t1 = fneg double %a
+  %t2 = fptrunc double %t1 to float
+  %t3 = fsub float %b, %t2
+  call void @use(float %t2)
+  ret float %t3
+}
+
 ; Extra uses should prevent the transform.
 
 define float @neg_trunc_op1_extra_uses(double %a, float %b) {
@@ -252,6 +364,21 @@ define float @neg_trunc_op1_extra_uses(d
   %t2 = fptrunc double %t1 to float
   %t3 = fsub float %b, %t2
   call void @use2(float %t2, double %t1)
+  ret float %t3
+}
+
+define float @unary_neg_trunc_op1_extra_uses(double %a, float %b) {
+; CHECK-LABEL: @unary_neg_trunc_op1_extra_uses(
+; CHECK-NEXT:    [[T1:%.*]] = fneg double [[A:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = fptrunc double [[T1]] to float
+; CHECK-NEXT:    [[T3:%.*]] = fsub float [[B:%.*]], [[T2]]
+; CHECK-NEXT:    call void @use2(float [[T2]], double [[T1]])
+; CHECK-NEXT:    ret float [[T3]]
+;
+  %t1 = fneg double %a
+  %t2 = fptrunc double %t1 to float
+  %t3 = fsub float %b, %t2
+  call void @use2(float %t2, double %t1)
   ret float %t3
 }
 

Modified: llvm/trunk/test/Transforms/InstCombine/known-never-nan.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/known-never-nan.ll?rev=361971&r1=361970&r2=361971&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/known-never-nan.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/known-never-nan.ll Wed May 29 08:21:28 2019
@@ -130,6 +130,17 @@ define i1 @nnan_fneg() {
   ret i1 %tmp
 }
 
+define i1 @nnan_unary_fneg() {
+; CHECK-LABEL: @nnan_unary_fneg(
+; CHECK-NEXT:    [[NNAN:%.*]] = call nnan double @func()
+; CHECK-NEXT:    ret i1 true
+;
+  %nnan = call nnan double @func()
+  %op = fneg double %nnan
+  %tmp = fcmp ord double %op, %op
+  ret i1 %tmp
+}
+
 define i1 @fpext_maybe_nan(float %arg0) {
 ; CHECK-LABEL: @fpext_maybe_nan(
 ; CHECK-NEXT:    [[TMP:%.*]] = fcmp ord float [[ARG0:%.*]], 0.000000e+00




More information about the llvm-commits mailing list