From 61b5773796c75e8021f9f476da49fc1c0a5dd1bb Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sat, 20 Jun 2020 09:52:12 -0400 Subject: [PATCH] [InstCombine] add tests for fabs(x) / fabs (x); NFC --- llvm/test/Transforms/InstCombine/fdiv.ll | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/fdiv.ll b/llvm/test/Transforms/InstCombine/fdiv.ll index 888f5e8f9c32..c5ea7413ab5e 100644 --- a/llvm/test/Transforms/InstCombine/fdiv.ll +++ b/llvm/test/Transforms/InstCombine/fdiv.ll @@ -1,6 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -instcombine < %s | FileCheck %s +declare float @llvm.fabs.f32(float) nounwind readnone + define float @exact_inverse(float %x) { ; CHECK-LABEL: @exact_inverse( ; CHECK-NEXT: [[DIV:%.*]] = fmul float [[X:%.*]], 1.250000e-01 @@ -570,3 +572,27 @@ define float @fdiv_fneg1_extra_use(float %x, float %y) { %div = fdiv float %neg, %y ret float %div } + +define float @fabs_same_op(float %x) { +; CHECK-LABEL: @fabs_same_op( +; CHECK-NEXT: [[A:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]]) +; CHECK-NEXT: [[R:%.*]] = fdiv float [[A]], [[A]] +; CHECK-NEXT: ret float [[R]] +; + %a = call float @llvm.fabs.f32(float %x) + %r = fdiv float %a, %a + ret float %r +} + +define float @fabs_same_op_extra_use(float %x) { +; CHECK-LABEL: @fabs_same_op_extra_use( +; CHECK-NEXT: [[A:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]]) +; CHECK-NEXT: call void @use_f32(float [[A]]) +; CHECK-NEXT: [[R:%.*]] = fdiv reassoc ninf float [[A]], [[A]] +; CHECK-NEXT: ret float [[R]] +; + %a = call float @llvm.fabs.f32(float %x) + call void @use_f32(float %a) + %r = fdiv ninf reassoc float %a, %a + ret float %r +}