57 lines · plain
1; RUN: opt -S -passes=instcombine -o - %s | FileCheck %s2 3; Test that fast math lib call simplification of double math function to float4; equivalent doesn't occur when the calling function matches the float5; equivalent math function. Otherwise this can cause the generation of infinite6; loops when compiled with -O2/3 and fast math.7 8; Test case C source:9;10; extern double exp(double x);11; inline float expf(float x) { return (float) exp((double) x); }12; float fn(float f) { return expf(f); }13;14; IR generated with command:15;16; clang -cc1 -O2 -ffast-math -emit-llvm -disable-llvm-passes -triple x86_64-unknown-unknown -o - <srcfile>17 18target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"19target triple = "x86_64-unknown-unknown"20 21; Function Attrs: nounwind22define float @fn(float %f) {23; CHECK: define float @fn(24; CHECK: call fast float @expf(25 %f.addr = alloca float, align 426 store float %f, ptr %f.addr, align 4, !tbaa !127 %1 = load float, ptr %f.addr, align 4, !tbaa !128 %call = call fast float @expf(float %1)29 ret float %call30}31 32; Function Attrs: inlinehint nounwind readnone33define available_externally float @expf(float %x) {34; CHECK: define available_externally float @expf(35; CHECK: fpext float36; CHECK: call fast double @exp(37; CHECK: fptrunc double38 %x.addr = alloca float, align 439 store float %x, ptr %x.addr, align 4, !tbaa !140 %1 = load float, ptr %x.addr, align 4, !tbaa !141 %conv = fpext float %1 to double42 %call = call fast double @exp(double %conv)43 %conv1 = fptrunc double %call to float44 ret float %conv145}46 47; Function Attrs: nounwind readnone48declare double @exp(double)49 50!llvm.ident = !{!0}51 52!0 = !{!"clang version 5.0.0"}53!1 = !{!2, !2, i64 0}54!2 = !{!"float", !3, i64 0}55!3 = !{!"omnipotent char", !4, i64 0}56!4 = !{!"Simple C/C++ TBAA"}57