From cc47b54243c395d88311ed1105e96cfaf2325f11 Mon Sep 17 00:00:00 2001 From: David Bolvansky Date: Wed, 7 Aug 2019 19:35:25 +0000 Subject: [PATCH] [NFC] Added tests for x/fabs(X) fold git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368200 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/fabs-copysign.ll | 75 ++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/Transforms/InstCombine/fabs-copysign.ll diff --git a/test/Transforms/InstCombine/fabs-copysign.ll b/test/Transforms/InstCombine/fabs-copysign.ll new file mode 100644 index 00000000000..d798b2d68b9 --- /dev/null +++ b/test/Transforms/InstCombine/fabs-copysign.ll @@ -0,0 +1,75 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -instcombine -S < %s | FileCheck %s + +declare double @llvm.fabs.f64(double) +declare float @llvm.fabs.f32(float) +declare void @use(double) + +declare double @llvm.copysign.f64(double, double) +declare float @llvm.copysign.f32(float, float) + +define double @fabs_copysign(double %x) { +; CHECK-LABEL: @fabs_copysign( +; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf double @llvm.copysign.f64(double 1.000000e+00, double [[X:%.*]]) +; CHECK-NEXT: ret double [[TMP1]] +; + %f = tail call double @llvm.fabs.f64(double %x) + %div = fdiv nnan ninf double %x, %f + ret double %div +} + + +define float @fabs_copysignf(float %x) { +; CHECK-LABEL: @fabs_copysignf( +; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf float @llvm.copysign.f32(float 1.000000e+00, float [[X:%.*]]) +; CHECK-NEXT: ret float [[TMP1]] +; + %f = tail call float @llvm.fabs.f32(float %x) + %div = fdiv nnan ninf float %x, %f + ret float %div +} + +define double @fabs_copysign_use(double %x) { +; CHECK-LABEL: @fabs_copysign_use( +; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf double @llvm.copysign.f64(double 1.000000e+00, double [[X:%.*]]) +; CHECK-NEXT: ret double [[TMP1]] +; + %f = tail call double @llvm.fabs.f64(double %x) + %div = fdiv nnan ninf double %x, %f + ret double %div +} + +; Negative tests + +define double @fabs_copysign_mismatch(double %x, double %y) { +; CHECK-LABEL: @fabs_copysign_mismatch( +; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[Y:%.*]]) +; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X:%.*]], [[F]] +; CHECK-NEXT: ret double [[DIV]] +; + %f = tail call double @llvm.fabs.f64(double %y) + %div = fdiv double %x, %f + ret double %div +} + +define double @fabs_copysign_no_nnan(double %x) { +; CHECK-LABEL: @fabs_copysign_no_nnan( +; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]]) +; CHECK-NEXT: [[DIV:%.*]] = fdiv ninf double [[X]], [[F]] +; CHECK-NEXT: ret double [[DIV]] +; + %f = tail call double @llvm.fabs.f64(double %x) + %div = fdiv ninf double %x, %f + ret double %div +} + +define double @fabs_copysign_no_ninf(double %x) { +; CHECK-LABEL: @fabs_copysign_no_ninf( +; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]]) +; CHECK-NEXT: [[DIV:%.*]] = fdiv nnan double [[X]], [[F]] +; CHECK-NEXT: ret double [[DIV]] +; + %f = tail call double @llvm.fabs.f64(double %x) + %div = fdiv nnan double %x, %f + ret double %div +} -- 2.40.0