From bfd172999be779cb441f40472f97646e4f73c2e7 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 22 Jun 2021 13:42:01 -0400 Subject: [PATCH] [InstCombine][test] add tests for FP min/max with negated op; NFC --- llvm/test/Transforms/InstCombine/maximum.ll | 35 +++++++++++++++++++++ llvm/test/Transforms/InstCombine/minimum.ll | 35 +++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/maximum.ll b/llvm/test/Transforms/InstCombine/maximum.ll index 1a0dfa11cfbb..70bf6a922857 100644 --- a/llvm/test/Transforms/InstCombine/maximum.ll +++ b/llvm/test/Transforms/InstCombine/maximum.ll @@ -411,3 +411,38 @@ define float @reduce_precision_fmf(float %x, float %y) { %trunc = fptrunc double %maximum to float ret float %trunc } + +define float @negated_op(float %x) { +; CHECK-LABEL: @negated_op( +; CHECK-NEXT: [[NEGX:%.*]] = fneg float [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = call float @llvm.maximum.f32(float [[X]], float [[NEGX]]) +; CHECK-NEXT: ret float [[R]] +; + %negx = fneg float %x + %r = call float @llvm.maximum.f32(float %x, float %negx) + ret float %r +} + +define <2 x double> @negated_op_fmf_commute_vec(<2 x double> %x) { +; CHECK-LABEL: @negated_op_fmf_commute_vec( +; CHECK-NEXT: [[NEGX:%.*]] = fneg <2 x double> [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = call nnan ninf nsz <2 x double> @llvm.maximum.v2f64(<2 x double> [[NEGX]], <2 x double> [[X]]) +; CHECK-NEXT: ret <2 x double> [[R]] +; + %negx = fneg <2 x double> %x + %r = call nsz nnan ninf <2 x double> @llvm.maximum.v2f64(<2 x double> %negx, <2 x double> %x) + ret <2 x double> %r +} + +define float @negated_op_extra_use(float %x) { +; CHECK-LABEL: @negated_op_extra_use( +; CHECK-NEXT: [[NEGX:%.*]] = fneg float [[X:%.*]] +; CHECK-NEXT: call void @use(float [[NEGX]]) +; CHECK-NEXT: [[R:%.*]] = call float @llvm.maximum.f32(float [[NEGX]], float [[X]]) +; CHECK-NEXT: ret float [[R]] +; + %negx = fneg float %x + call void @use(float %negx) + %r = call float @llvm.maximum.f32(float %negx, float %x) + ret float %r +} diff --git a/llvm/test/Transforms/InstCombine/minimum.ll b/llvm/test/Transforms/InstCombine/minimum.ll index cc2fe28af452..2c12792713b7 100644 --- a/llvm/test/Transforms/InstCombine/minimum.ll +++ b/llvm/test/Transforms/InstCombine/minimum.ll @@ -436,3 +436,38 @@ define float @reduce_precision_fmf(float %x, float %y) { %trunc = fptrunc double %minimum to float ret float %trunc } + +define float @negated_op(float %x) { +; CHECK-LABEL: @negated_op( +; CHECK-NEXT: [[NEGX:%.*]] = fneg float [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = call float @llvm.minimum.f32(float [[X]], float [[NEGX]]) +; CHECK-NEXT: ret float [[R]] +; + %negx = fneg float %x + %r = call float @llvm.minimum.f32(float %x, float %negx) + ret float %r +} + +define <2 x double> @negated_op_fmf_commute_vec(<2 x double> %x) { +; CHECK-LABEL: @negated_op_fmf_commute_vec( +; CHECK-NEXT: [[NEGX:%.*]] = fneg <2 x double> [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = call nnan ninf nsz <2 x double> @llvm.minimum.v2f64(<2 x double> [[NEGX]], <2 x double> [[X]]) +; CHECK-NEXT: ret <2 x double> [[R]] +; + %negx = fneg <2 x double> %x + %r = call nsz nnan ninf <2 x double> @llvm.minimum.v2f64(<2 x double> %negx, <2 x double> %x) + ret <2 x double> %r +} + +define double @negated_op_extra_use(double %x) { +; CHECK-LABEL: @negated_op_extra_use( +; CHECK-NEXT: [[NEGX:%.*]] = fneg double [[X:%.*]] +; CHECK-NEXT: call void @use(double [[NEGX]]) +; CHECK-NEXT: [[R:%.*]] = call double @llvm.minimum.f64(double [[NEGX]], double [[X]]) +; CHECK-NEXT: ret double [[R]] +; + %negx = fneg double %x + call void @use(double %negx) + %r = call double @llvm.minimum.f64(double %negx, double %x) + ret double %r +}