Hi Devs, going by this link https://llvm.org/docs/LangRef.html#floatenv it says that floating point operation does not have side effects by defaults. but when compile a test case i.e. cat a.c float foo(float a, float b) { return a+b; } $clang a.c -O2 -S -emit-llvm emit ir like: $cat a.ll --------------------------------------- ; ModuleID = 'a.c' source_filename = "a.c" target datalayout "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" ; Function Attrs: norecurse nounwind readnone uwtable define dso_local float @foo(float %a, float %b) local_unnamed_addr #0 { entry: %add = fadd float %a, %b ret float %add } attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } --------------------- and the setting "no-trapping-math"="false" should mean -ftrapping-math but it does not and it also contradict with documentation. I think clang should emit this "no-trapping-math"="true" by default if it goes with this assumption https://llvm.org/docs/LangRef.html#floatenv ? what is default behavior of clang -fno-trapping-math or -ftrapping-math? also clang default behavior does not match gcc? https://godbolt.org/z/B3YvxE ./kamlesh -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200527/85c57d10/attachment.html>
kamlesh kumar via llvm-dev
2020-May-27 05:38 UTC
[llvm-dev] By default clang does not emit trap insn
On Wed, May 27, 2020 at 11:06 AM kamlesh kumar <kamleshbhalui at gmail.com> wrote:> Hi Devs, > going by this link https://llvm.org/docs/LangRef.html#floatenv > it says that floating point operation does not have side effects by > defaults. > but when compile a test case > i.e. > cat a.c > float foo(float a, float b) > { > return a+b; > } > > $clang a.c -O2 -S -emit-llvm > emit ir like: > $cat a.ll > --------------------------------------- > ; ModuleID = 'a.c' > source_filename = "a.c" > target datalayout > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" > target triple = "x86_64-unknown-linux-gnu" > > ; Function Attrs: norecurse nounwind readnone uwtable > define dso_local float @foo(float %a, float %b) local_unnamed_addr #0 { > entry: > %add = fadd float %a, %b > ret float %add > } > > attributes #0 = { norecurse nounwind readnone uwtable > "correctly-rounded-divide-sqrt-fp-math"="false" > "disable-tail-calls"="false" "frame-pointer"="none" > "less-precise-fpmad"="false" "min-legal-vector-width"="0" > "no-infs-fp-math"="false" "no-jump-tables"="false" > "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" > "no-trapping-math"="false" "stack-protector-buffer-size"="8" > "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" > "unsafe-fp-math"="false" "use-soft-float"="false" } > --------------------- > and the setting "no-trapping-math"="false" should mean -ftrapping-math but > it does not and it also contradict with documentation. > > I think clang should emit this "no-trapping-math"="true" by default if it > goes with this assumption https://llvm.org/docs/LangRef.html#floatenv ? > what is default behavior of clang -fno-trapping-math or -ftrapping-math? > also clang default behavior does not match gcc? > https://godbolt.org/z/B3YvxE > > ./kamlesh > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200527/2de7a716/attachment.html>
I believe support for trapping math is experimental/work in progress: https://reviews.llvm.org/D62731 On Tue, May 26, 2020 at 10:36 PM kamlesh kumar via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi Devs, > going by this link https://llvm.org/docs/LangRef.html#floatenv > it says that floating point operation does not have side effects by > defaults. > but when compile a test case > i.e. > cat a.c > float foo(float a, float b) > { > return a+b; > } > > $clang a.c -O2 -S -emit-llvm > emit ir like: > $cat a.ll > --------------------------------------- > ; ModuleID = 'a.c' > source_filename = "a.c" > target datalayout > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" > target triple = "x86_64-unknown-linux-gnu" > > ; Function Attrs: norecurse nounwind readnone uwtable > define dso_local float @foo(float %a, float %b) local_unnamed_addr #0 { > entry: > %add = fadd float %a, %b > ret float %add > } > > attributes #0 = { norecurse nounwind readnone uwtable > "correctly-rounded-divide-sqrt-fp-math"="false" > "disable-tail-calls"="false" "frame-pointer"="none" > "less-precise-fpmad"="false" "min-legal-vector-width"="0" > "no-infs-fp-math"="false" "no-jump-tables"="false" > "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" > "no-trapping-math"="false" "stack-protector-buffer-size"="8" > "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" > "unsafe-fp-math"="false" "use-soft-float"="false" } > --------------------- > and the setting "no-trapping-math"="false" should mean -ftrapping-math but > it does not and it also contradict with documentation. > > I think clang should emit this "no-trapping-math"="true" by default if it > goes with this assumption https://llvm.org/docs/LangRef.html#floatenv ? > what is default behavior of clang -fno-trapping-math or -ftrapping-math? > also clang default behavior does not match gcc? > https://godbolt.org/z/B3YvxE > > ./kamlesh > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200526/27634b93/attachment.html>
David Blaikie via llvm-dev
2020-May-27 06:11 UTC
[llvm-dev] By default clang does not emit trap insn
looks like experimental/work in progress support: https://reviews.llvm.org/D62731 On Tue, May 26, 2020 at 10:39 PM kamlesh kumar via llvm-dev < llvm-dev at lists.llvm.org> wrote:> > > On Wed, May 27, 2020 at 11:06 AM kamlesh kumar <kamleshbhalui at gmail.com> > wrote: > >> Hi Devs, >> going by this link https://llvm.org/docs/LangRef.html#floatenv >> it says that floating point operation does not have side effects by >> defaults. >> but when compile a test case >> i.e. >> cat a.c >> float foo(float a, float b) >> { >> return a+b; >> } >> >> $clang a.c -O2 -S -emit-llvm >> emit ir like: >> $cat a.ll >> --------------------------------------- >> ; ModuleID = 'a.c' >> source_filename = "a.c" >> target datalayout >> "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" >> target triple = "x86_64-unknown-linux-gnu" >> >> ; Function Attrs: norecurse nounwind readnone uwtable >> define dso_local float @foo(float %a, float %b) local_unnamed_addr #0 { >> entry: >> %add = fadd float %a, %b >> ret float %add >> } >> >> attributes #0 = { norecurse nounwind readnone uwtable >> "correctly-rounded-divide-sqrt-fp-math"="false" >> "disable-tail-calls"="false" "frame-pointer"="none" >> "less-precise-fpmad"="false" "min-legal-vector-width"="0" >> "no-infs-fp-math"="false" "no-jump-tables"="false" >> "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" >> "no-trapping-math"="false" "stack-protector-buffer-size"="8" >> "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" >> "unsafe-fp-math"="false" "use-soft-float"="false" } >> --------------------- >> and the setting "no-trapping-math"="false" should mean -ftrapping-math >> but it does not and it also contradict with documentation. >> >> I think clang should emit this "no-trapping-math"="true" by default if it >> goes with this assumption https://llvm.org/docs/LangRef.html#floatenv ? >> what is default behavior of clang -fno-trapping-math or -ftrapping-math? >> also clang default behavior does not match gcc? >> https://godbolt.org/z/B3YvxE >> >> ./kamlesh >> >> >> _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200526/df6cbb8c/attachment.html>
On Wed, May 27, 2020 at 1:36 AM kamlesh kumar via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Hi Devs, > going by this link https://llvm.org/docs/LangRef.html#floatenv > it says that floating point operation does not have side effects by defaults. > but when compile a test case > i.e. > cat a.c > float foo(float a, float b) > { > return a+b; > } > > $clang a.c -O2 -S -emit-llvm > emit ir like: > $cat a.ll > --------------------------------------- > ; ModuleID = 'a.c' > source_filename = "a.c" > target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" > target triple = "x86_64-unknown-linux-gnu" > > ; Function Attrs: norecurse nounwind readnone uwtable > define dso_local float @foo(float %a, float %b) local_unnamed_addr #0 { > entry: > %add = fadd float %a, %b > ret float %add > } > > attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } > --------------------- > and the setting "no-trapping-math"="false" should mean -ftrapping-math but it does not and it also contradict with documentation. > > I think clang should emit this "no-trapping-math"="true" by default if it goes with this assumption https://llvm.org/docs/LangRef.html#floatenv ? > what is default behavior of clang -fno-trapping-math or -ftrapping-math? > also clang default behavior does not match gcc? > https://godbolt.org/z/B3YvxEHi Kamlesh, I haven't looked in a few months, but IINM, -trapping-math is a no-op in LLVM. But yes, what you found is confusing and should be sorted out. The front end currently generates experimental constrained intrinsics if -ftrapping-math is present on the command line. If you want to generate trap-safe code, you could try that option or -ffp-model/-ffp-exception-behavior depending on your needs. https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffp-model -Cam
Seemingly Similar Threads
- default behavior or
- Reassociation is blocking a vectorization
- LLVM 11 and trunk selecting 4 wide instead of 8 wide loop vectorization for AVX-enabled target
- LLVM 11 and trunk selecting 4 wide instead of 8 wide loop vectorization for AVX-enabled target
- LLC crash while handling DEBUG info