OSDN Git Service

[InstCombine] add tests and comments for fdiv X, C; NFC
authorSanjay Patel <spatel@rotateright.com>
Wed, 14 Feb 2018 19:54:51 +0000 (19:54 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 14 Feb 2018 19:54:51 +0000 (19:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325161 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/InstCombine/fdiv.ll

index b94cfcb..ac9733b 100644 (file)
@@ -1,8 +1,19 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S -instcombine < %s | FileCheck %s
 
-define float @test1(float %x) {
-; CHECK-LABEL: @test1(
+define float @exact_inverse(float %x) {
+; CHECK-LABEL: @exact_inverse(
+; CHECK-NEXT:    [[DIV:%.*]] = fmul float [[X:%.*]], 1.250000e-01
+; CHECK-NEXT:    ret float [[DIV]]
+;
+  %div = fdiv float %x, 8.0
+  ret float %div
+}
+
+; Min normal float = 1.17549435E-38
+
+define float @exact_inverse2(float %x) {
+; CHECK-LABEL: @exact_inverse2(
 ; CHECK-NEXT:    [[DIV:%.*]] = fmul float [[X:%.*]], 0x47D0000000000000
 ; CHECK-NEXT:    ret float [[DIV]]
 ;
@@ -10,8 +21,10 @@ define float @test1(float %x) {
   ret float %div
 }
 
-define float @test2(float %x) {
-; CHECK-LABEL: @test2(
+; Max exponent = 1.70141183E+38; don't transform to multiply with denormal.
+
+define float @exact_inverse_but_denorm(float %x) {
+; CHECK-LABEL: @exact_inverse_but_denorm(
 ; CHECK-NEXT:    [[DIV:%.*]] = fdiv float [[X:%.*]], 0x47E0000000000000
 ; CHECK-NEXT:    ret float [[DIV]]
 ;
@@ -19,8 +32,10 @@ define float @test2(float %x) {
   ret float %div
 }
 
-define float @test3(float %x) {
-; CHECK-LABEL: @test3(
+; Denormal = float 1.40129846E-45; inverse can't be represented.
+
+define float @not_exact_inverse2(float %x) {
+; CHECK-LABEL: @not_exact_inverse2(
 ; CHECK-NEXT:    [[DIV:%.*]] = fdiv float [[X:%.*]], 0x36A0000000000000
 ; CHECK-NEXT:    ret float [[DIV]]
 ;
@@ -28,15 +43,67 @@ define float @test3(float %x) {
   ret float %div
 }
 
-define float @test4(float %x) {
-; CHECK-LABEL: @test4(
-; CHECK-NEXT:    [[DIV:%.*]] = fmul fast float [[X:%.*]], 1.250000e-01
+; Fast math allows us to replace this fdiv.
+
+define float @not_exact_but_allow_recip(float %x) {
+; CHECK-LABEL: @not_exact_but_allow_recip(
+; CHECK-NEXT:    [[DIV:%.*]] = fmul arcp float [[X:%.*]], 0x3FD5555560000000
+; CHECK-NEXT:    ret float [[DIV]]
+;
+  %div = fdiv arcp float %x, 3.0
+  ret float %div
+}
+
+; Fast math allows us to replace this fdiv, but we don't to avoid a denormal.
+; TODO: What if the function attributes tell us that denormals are flushed?
+
+define float @not_exact_but_allow_recip_but_denorm(float %x) {
+; CHECK-LABEL: @not_exact_but_allow_recip_but_denorm(
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv arcp float [[X:%.*]], 0x47E0000100000000
 ; CHECK-NEXT:    ret float [[DIV]]
 ;
-  %div = fdiv fast float %x, 8.0
+  %div = fdiv arcp float %x, 0x47E0000100000000
   ret float %div
 }
 
+; FIXME: Vector neglect.
+
+define <2 x float> @exact_inverse_splat(<2 x float> %x) {
+; CHECK-LABEL: @exact_inverse_splat(
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv <2 x float> [[X:%.*]], <float 4.000000e+00, float 4.000000e+00>
+; CHECK-NEXT:    ret <2 x float> [[DIV]]
+;
+  %div = fdiv <2 x float> %x, <float 4.0, float 4.0>
+  ret <2 x float> %div
+}
+
+define <2 x float> @exact_inverse_vec(<2 x float> %x) {
+; CHECK-LABEL: @exact_inverse_vec(
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv <2 x float> [[X:%.*]], <float 4.000000e+00, float 8.000000e+00>
+; CHECK-NEXT:    ret <2 x float> [[DIV]]
+;
+  %div = fdiv <2 x float> %x, <float 4.0, float 8.0>
+  ret <2 x float> %div
+}
+
+define <2 x float> @not_exact_inverse_splat(<2 x float> %x) {
+; CHECK-LABEL: @not_exact_inverse_splat(
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv <2 x float> [[X:%.*]], <float 3.000000e+00, float 3.000000e+00>
+; CHECK-NEXT:    ret <2 x float> [[DIV]]
+;
+  %div = fdiv <2 x float> %x, <float 3.0, float 3.0>
+  ret <2 x float> %div
+}
+
+define <2 x float> @not_exact_inverse_vec(<2 x float> %x) {
+; CHECK-LABEL: @not_exact_inverse_vec(
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv <2 x float> [[X:%.*]], <float 4.000000e+00, float 3.000000e+00>
+; CHECK-NEXT:    ret <2 x float> [[DIV]]
+;
+  %div = fdiv <2 x float> %x, <float 4.0, float 3.0>
+  ret <2 x float> %div
+}
+
 define float @test5(float %x, float %y, float %z) {
 ; CHECK-LABEL: @test5(
 ; CHECK-NEXT:    [[TMP1:%.*]] = fmul fast float [[Y:%.*]], [[Z:%.*]]