From ec0d98156cdfa010b029c88075d56e414db885fb Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Wed, 1 Jan 2020 19:19:08 +0000 Subject: [PATCH] * use maytrap instead of strict FP exception behaviour in LLVM, so constant propagation is still allowed git-svn-id: trunk@43832 - --- compiler/llvm/aasmllvmmetadata.pas | 2 +- compiler/llvm/hlcgllvm.pas | 4 +++- compiler/llvm/nllvmadd.pas | 6 ++++-- compiler/llvm/nllvminl.pas | 10 +++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/llvm/aasmllvmmetadata.pas b/compiler/llvm/aasmllvmmetadata.pas index b0710d19e8..b99f5572a0 100644 --- a/compiler/llvm/aasmllvmmetadata.pas +++ b/compiler/llvm/aasmllvmmetadata.pas @@ -146,7 +146,7 @@ implementation function llvm_constrainedexceptmodestring: ansistring; begin if not(cs_opt_fastmath in current_settings.optimizerswitches) then - result:='fpexcept.strict' + result:='fpexcept.maytrap' else result:='fpexcept.ignore' end; diff --git a/compiler/llvm/hlcgllvm.pas b/compiler/llvm/hlcgllvm.pas index 85593e4c4c..558c4d82fe 100644 --- a/compiler/llvm/hlcgllvm.pas +++ b/compiler/llvm/hlcgllvm.pas @@ -1346,6 +1346,7 @@ implementation procedure thlcgllvm.gen_fpconstrained_intrinsic(list: TAsmList; const intrinsic: TIDString; fromsize, tosize: tdef; fromreg, toreg: tregister; roundingmode: boolean); var + exceptmode: ansistring; frompara, roundpara, exceptpara, respara: tcgpara; tmploc: tlocation; pd: tprocdef; @@ -1370,7 +1371,8 @@ implementation gen_load_loc_cgpara(list,fromsize,tmploc,frompara); if roundingmode then a_load_reg_cgpara(list,llvm_metadatatype,tllvmmetadata.getstringreg('round.dynamic'),roundpara); - a_load_reg_cgpara(list,llvm_metadatatype,tllvmmetadata.getstringreg('fpexcept.strict'),exceptpara); + exceptmode:=llvm_constrainedexceptmodestring; + a_load_reg_cgpara(list,llvm_metadatatype,tllvmmetadata.getstringreg(exceptmode),exceptpara); if roundingmode then respara:=g_call_system_proc(list,pd,[@frompara,@roundpara,@exceptpara],nil) else diff --git a/compiler/llvm/nllvmadd.pas b/compiler/llvm/nllvmadd.pas index aeeebdc681..5c32e86255 100644 --- a/compiler/llvm/nllvmadd.pas +++ b/compiler/llvm/nllvmadd.pas @@ -50,7 +50,7 @@ implementation verbose,globtype,globals,cutils, aasmdata, symconst,symtype,symdef,defutil, - llvmbase,aasmllvm, + llvmbase,aasmllvm,aasmllvmmetadata, cgbase,cgutils,pass_1, hlcgobj, nadd,ncal,ncnv,ncon @@ -60,6 +60,7 @@ implementation function tllvmaddnode.pass_1: tnode; var + exceptmode: ansistring; intrname: string; iscompcurrency: boolean; begin @@ -98,8 +99,9 @@ implementation inserttypeconv_internal(left,s80floattype); inserttypeconv_internal(right,s80floattype); end; + exceptmode:=llvm_constrainedexceptmodestring; result:=ccallnode.createintern(intrname, - ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar('fpexcept.strict'),length('fpexcept.strict'),llvm_metadatatype), + ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar(exceptmode),length(exceptmode),llvm_metadatatype), ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar('round.dynamic'),length('round.dynamic'),llvm_metadatatype), ccallparanode.create(right, ccallparanode.create(left,nil) diff --git a/compiler/llvm/nllvminl.pas b/compiler/llvm/nllvminl.pas index 7654f95c63..2b63690d7c 100644 --- a/compiler/llvm/nllvminl.pas +++ b/compiler/llvm/nllvminl.pas @@ -61,7 +61,7 @@ implementation pass_2, cgbase,cgutils,tgobj,hlcgobj, cpubase, - llvmbase,aasmllvm; + llvmbase,aasmllvm,aasmllvmmetadata; procedure tllvminlinenode.maybe_remove_round_trunc_typeconv; var @@ -220,6 +220,7 @@ implementation function tllvminlinenode.first_fma: tnode; var + exceptmode: ansistring; procname: string[40]; begin if cs_opt_fastmath in current_settings.optimizerswitches then @@ -249,8 +250,9 @@ implementation else internalerror(2019122811); end; + exceptmode:=llvm_constrainedexceptmodestring; result:=ccallnode.createintern(procname, - ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar('fpexcept.strict'),length('fpexcept.strict'),llvm_metadatatype), + ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar(exceptmode),length(exceptmode),llvm_metadatatype), ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar('round.dynamic'),length('round.dynamic'),llvm_metadatatype), left ) @@ -273,6 +275,7 @@ implementation function tllvminlinenode.first_sqrt_real: tnode; var + exceptmode: ansistring; intrinsic: string[40]; begin if left.resultdef.typ<>floatdef then @@ -304,8 +307,9 @@ implementation else internalerror(2019122810); end; + exceptmode:=llvm_constrainedexceptmodestring; result:=ccallnode.createintern(intrinsic, - ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar('fpexcept.strict'),length('fpexcept.strict'),llvm_metadatatype), + ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar(exceptmode),length(exceptmode),llvm_metadatatype), ccallparanode.create(cstringconstnode.createpchar(ansistring2pchar('round.dynamic'),length('round.dynamic'),llvm_metadatatype), ccallparanode.create(left,nil) )