[LLVMbugs] [Bug 17850] New: missed opportunities to use lower precision cmath functions
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Nov 8 12:59:12 PST 2013
http://llvm.org/bugs/show_bug.cgi?id=17850
Bug ID: 17850
Summary: missed opportunities to use lower precision cmath
functions
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Transformation Utilities
Assignee: unassignedbugs at nondot.org
Reporter: kkhoo at perfwizard.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
LLVM isn't optimizing math.h/cmath library calls based on precision of the
inputs and outputs:
$ cat ~/Desktop/cos.c
#include <math.h>
float foo(float x) { return cos(x); }
$ ./clang -O3 -S -o - ~/Desktop/cos.c
...
cvtss2sd %xmm0, %xmm0
callq _cos
cvtsd2ss %xmm0, %xmm0
popq %rbp
ret
...
GCC gets rid of the precision conversions and makes this a call to _cosf.
Based on the code in LibCallSimplifierImpl::lookupOptimization(), it appears
that LLVM should be making this optimization assuming unsafe math, but there's
no difference if I use -ffast-math.
So there are 2 potential bugs here:
1. Why is LLVM failing to optimize this code with fast-math?
2. Why doesn't LLVM do this optimization regardless of fast-math (unsafe FP)?
This is with:
$ ./clang -v
clang version 3.4 (trunk 194153)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
And here's the IR:
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.7.0"
; Function Attrs: nounwind readnone ssp uwtable
define float @foo(float %x) #0 {
entry:
%conv = fpext float %x to double
%call = tail call double @cos(double %conv) #2
%conv1 = fptrunc double %call to float
ret float %conv1
}
; Function Attrs: nounwind readnone
declare double @cos(double) #1
attributes #0 = { nounwind readnone ssp uwtable "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-nans-fp-math"="false"
"stack-protector-buffer-size"="8" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { nounwind readnone "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-nans-fp-math"="false"
"stack-protector-buffer-size"="8" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #2 = { nounwind readnone }
!llvm.ident = !{!0}
!0 = metadata !{metadata !"clang version 3.4 (trunk 194153)"}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131108/a22c9d21/attachment.html>
More information about the llvm-bugs
mailing list