From 17f939474ec259b453a7e28696b5b571148b68b9 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sat, 13 Feb 2021 11:00:55 -0500 Subject: [PATCH] [InstCombine] add tests for pow() divisor; NFC --- test/Transforms/InstCombine/fdiv.ll | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/Transforms/InstCombine/fdiv.ll b/test/Transforms/InstCombine/fdiv.ll index 7b1a556439b..f1858cb7bb0 100644 --- a/test/Transforms/InstCombine/fdiv.ll +++ b/test/Transforms/InstCombine/fdiv.ll @@ -2,6 +2,8 @@ ; RUN: opt -S -instcombine < %s | FileCheck %s declare float @llvm.fabs.f32(float) nounwind readnone +declare float @llvm.pow.f32(float, float) nounwind readnone +declare <2 x half> @llvm.pow.v2f16(<2 x half>, <2 x half>) nounwind readnone define float @exact_inverse(float %x) { ; CHECK-LABEL: @exact_inverse( @@ -656,3 +658,60 @@ define float @fabs_fabs_extra_use3(float %x, float %y) { %r = fdiv float %x.fabs, %y.fabs ret float %r } + +define float @pow_divisor(float %x, float %y, float %z) { +; CHECK-LABEL: @pow_divisor( +; CHECK-NEXT: [[P:%.*]] = call float @llvm.pow.f32(float [[X:%.*]], float [[Y:%.*]]) +; CHECK-NEXT: [[R:%.*]] = fdiv reassoc arcp float [[Z:%.*]], [[P]] +; CHECK-NEXT: ret float [[R]] +; + %p = call float @llvm.pow.f32(float %x, float %y) + %r = fdiv reassoc arcp float %z, %p + ret float %r +} + +define float @pow_divisor_extra_use(float %x, float %y, float %z) { +; CHECK-LABEL: @pow_divisor_extra_use( +; CHECK-NEXT: [[P:%.*]] = call float @llvm.pow.f32(float [[X:%.*]], float [[Y:%.*]]) +; CHECK-NEXT: call void @use_f32(float [[P]]) +; CHECK-NEXT: [[R:%.*]] = fdiv reassoc arcp float [[Z:%.*]], [[P]] +; CHECK-NEXT: ret float [[R]] +; + %p = call float @llvm.pow.f32(float %x, float %y) + call void @use_f32(float %p) + %r = fdiv reassoc arcp float %z, %p + ret float %r +} + +define float @pow_divisor_not_enough_fmf(float %x, float %y, float %z) { +; CHECK-LABEL: @pow_divisor_not_enough_fmf( +; CHECK-NEXT: [[P:%.*]] = call fast float @llvm.pow.f32(float [[X:%.*]], float [[Y:%.*]]) +; CHECK-NEXT: [[R:%.*]] = fdiv reassoc float [[Z:%.*]], [[P]] +; CHECK-NEXT: ret float [[R]] +; + %p = call fast float @llvm.pow.f32(float %x, float %y) + %r = fdiv reassoc float %z, %p + ret float %r +} + +define float @pow_divisor_not_enough_fmf2(float %x, float %y, float %z) { +; CHECK-LABEL: @pow_divisor_not_enough_fmf2( +; CHECK-NEXT: [[P:%.*]] = call fast float @llvm.pow.f32(float [[X:%.*]], float [[Y:%.*]]) +; CHECK-NEXT: [[R:%.*]] = fdiv arcp float [[Z:%.*]], [[P]] +; CHECK-NEXT: ret float [[R]] +; + %p = call fast float @llvm.pow.f32(float %x, float %y) + %r = fdiv arcp float %z, %p + ret float %r +} + +define <2 x half> @pow_recip(<2 x half> %x, <2 x half> %y) { +; CHECK-LABEL: @pow_recip( +; CHECK-NEXT: [[P:%.*]] = call <2 x half> @llvm.pow.v2f16(<2 x half> [[X:%.*]], <2 x half> [[Y:%.*]]) +; CHECK-NEXT: [[R:%.*]] = fdiv reassoc ninf arcp <2 x half> , [[P]] +; CHECK-NEXT: ret <2 x half> [[R]] +; + %p = call <2 x half> @llvm.pow.v2f16(<2 x half> %x, <2 x half> %y) + %r = fdiv reassoc arcp ninf <2 x half> , %p + ret <2 x half> %r +}