Enable constant propagation for more math functions

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 25 21:49:56 PDT 2015


Hi Erik,

Thanks for the patch! I have a few comments --

>>     case 'a':
>> -    return Name == "acos" || Name == "asin" || Name == "atan" || Name =="atan2";
>> +    return Name == "acos" || Name == "asin" || Name == "atan" ||
>> +      Name =="atan2" || Name == "acosf" || Name == "asinf" || Name == "atanf" ||
>> +      Name =="atan2f";


This is fine for now.

A note for later: I've noticed that there is a pattern in llvm where we use long chains of short-circuited string comparisons (e.g StringSwitch). We should have a variant of StringSwitch which runs in time proportional to the length of the longest string in the switch, instead of the number of strings in the switch. A fast, easy-to-use, trie-backed interface would be ideal. This would be a good place to use it.

>> +define float @test_atan2f() nounwind uwtable ssp {
>> +entry:
>> +; CHECK-LABEL: @test_atan2f(
>> +; CHECK-NOT: call
>> +  %0 = call float @atan2f(float 3.000000e+00, float 4.000000e+00)
>> +  ret float %0
>> +}
>> 
>> +; Shouldn't fold because of -fno-builtin
>> +define float @atan2f_() nounwind uwtable ssp {
>> +; FNOBUILTIN-LABEL: @atan2f_(
>> +; FNOBUILTIN: %1 = call float @atan2f(float 3.000000e+00, float 4.000000e+00)
>> +  %1 = call float @atan2f(float 3.000000e+00, float 4.000000e+00)
>> +  ret float %1
>> +}

I've noticed many pairs of test functions like the one above. Can this pair be combined into one function? E.g:

>> +define float @atan2f_() nounwind uwtable ssp {
>> +; CHECK-LABEL: @_atan2f(
>> +; FNOBUILTIN-LABEL: @atan2f_(
>> +; CHECK-NOT: call
>> +; FNOBUILTIN: %1 = call float @atan2f(float 3.000000e+00, float 4.000000e+00)
>> +  %1 = call float @atan2f(float 3.000000e+00, float 4.000000e+00)
>> +  ret float %1
>> +}

If so, it would be nice to reduce the test case size. Apart from that, please run clang-format -style=llvm on your changes. Everything else looks good.

vedant

On Aug 25, 2015, at 1:14 PM, Erik Schnetter via llvm-commits <llvm-commits at lists.llvm.org> wrote:

> It seems that constant propagation for single precision math functions (such as tanf) is already working, but was not enabled. This patch enables these for many single-precision functions, and adds respective test cases.
> 
> List of newly handled functions: acosf asinf atanf atan2f ceilf coshf expf exp2f fabsf floorf fmodf logf log10f powf sinhf tanf tanhf
> 
> -erik
> 
> -- 
> Erik Schnetter <schnetter at gmail.com> http://www.perimeterinstitute.ca/personal/eschnetter/
> <constprop.diff>_______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=nRkKAYlatRp-Wgk-tAtmRg&m=zIeTq7C24I26_ny62rhiVNnPUKhiL-ttf5E5SdvSYfM&s=hnzB8DZ-EJj3yM7S-bYX5mwxBMka0n18KAACB3fEHcQ&e= 



More information about the llvm-commits mailing list