Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 8 stopped optimizing pow(2., x) to exp2(x) #39887

Closed
llvmbot opened this issue Jan 30, 2019 · 21 comments
Closed

LLVM 8 stopped optimizing pow(2., x) to exp2(x) #39887

llvmbot opened this issue Jan 30, 2019 · 21 comments
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 30, 2019

Bugzilla Link 40541
Resolution FIXED
Resolved on Feb 13, 2019 08:25
Version 8.0
OS Windows NT
Blocks #39678
Reporter LLVM Bugzilla Contributor
CC @efriedma-quic,@froydnj,@zmodem,@glandium,@zygoloid,@rnk,@rotateright

Extended Description

We noticed this on 32-bit clang-cl builds.

#include
float foo(double d) { return pow(2., d / 1200.); }

d:\clang7.0.1\bin\clang-cl -m32 -O2 -c exp2.cpp
dumpbin /all exp2.obj | findstr REL32
00000017 REL32 00000000 F _exp2

d:\clang8rc1\bin\clang-cl -m32 -O2 -c exp2.cpp
dumpbin /all exp2.obj | findstr REL32
0000002C REL32 00000000 11 _pow

At first glance I'm suspecting a bug in 2123ea7.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 31, 2019

Indeed, that patch fixed an issue when the call to exp2() would be emitted even when the run time environment didn't support it.

LLVM assumes that Win32 only supports C89 math functions, which doesn't seem to be the case for a while anymore: https://is.gd/xFJPQw

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 31, 2019

Is this something that could be safely fixed within the 8.0.0 release?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 31, 2019

I'm afraid that, as an enhancement, as you indicated above, it's too late for 8.0, since only bug fixes are being accepted now.

My impression is that the Win32 library info needs an update, but, not working on targeting Windows, I'm unaware of how this would change the minimum requirements of LLVM in this OS.

At https://is.gd/hTHTvX, it states that at least VC2015 is required to build LLVM. In my opinion, retargeting the Windows support to this version would be sensible, at least from what I could glean about it, albeit only on x86.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 31, 2019

Reading the documentation in VS a bit more carefully, it seems that it still supports only C89. exp2() was not defined by C89, so LLVM uses this information describing run time library support that it assumes for Windows. However, reading the info on exp2() at https://is.gd/xFJPQw, it seems that VS supports a variation of C89. Specifically, just the double precision exp2().

I'll try to inventory the variations in the math library later.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 1, 2019

Patch at https://reviews.llvm.org/D57625.

@rnk
Copy link
Collaborator

rnk commented Feb 5, 2019

If this was a regression, have we identified the commit that caused this? I ask because I want to try to understand if this change was intended behavior.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 5, 2019

If this was a regression, have we identified the commit that caused this? I
ask because I want to try to understand if this change was intended behavior.

r341095, primarily about expanding the optimizations around pow, additionally fixed a bug where exp2 would be emitted even when the TargetLibraryInfo didn't support it. Turns out Windows builds were inadvertently relying on that behavior, because that target (wrongly) thinks exp2 isn't supported.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 5, 2019

David,

Could you please provide the output when running either clang-cl command above with the option --verbose?

Thank you.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 6, 2019

Do you mean -v? The --verbose option isn't recognized. What part of the output are you looking for?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 6, 2019

OK, could you please build an executable and provide a verbose output showing both how the compiler is invoked and all the libraries linked in?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 6, 2019

It would save us some round trips if you'd spell out precisely what command you'd like me to run, otherwise I am likely to misunderstand your request.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 6, 2019

Sorry, I'm not a Windows user. Based on the clang documentation, here's what I think the commands should be.

Please, try:

clang-cl -m32 -O2 -c exp2.cpp -o exp2.o -v

And then:

clang-cl -m32 exp2.o -o exp2.exe -v

Thank you.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 6, 2019

E:\repro\exp2>type exp2.cpp
#include

int main(int argc, char** argv) {
return pow(2., argc);
}

E:\repro\exp2>d:\clang8rc1\bin\clang-cl -m32 -O2 -c exp2.cpp -o exp2.o -v
clang version 8.0.0 (tags/RELEASE_800/rc1 352000)
Target: i386-pc-windows-msvc
Thread model: posix
InstalledDir: d:\clang8rc1\bin
"d:\clang8rc1\bin\clang-cl.exe" -cc1 -triple i386-pc-windows-msvc19.16.27026 -emit-obj -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name exp2.cpp -mrelocation-model static -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -mllvm -x86-asm-syntax=intel -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fms-volatile -fdiagnostics-format msvc -dwarf-column-info -momit-leaf-frame-pointer -v -ffunction-sections -coverage-notes-file "E:\repro\exp2\exp2.gcno" -resource-dir "d:\clang8rc1\lib\clang\8.0.0" -internal-isystem "d:\clang8rc1\lib\clang\8.0.0\include" -internal-isystem "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" -O2 -fdeprecated-macro -fdebug-compilation-dir "E:\repro\exp2" -ferror-limit 19 -fmessage-length 120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.16.27026 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o exp2.o -x c++ exp2.cpp -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
d:\clang8rc1\lib\clang\8.0.0\include
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt
C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared
C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um
C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt
End of search list.

E:\repro\exp2>d:\clang8rc1\bin\clang-cl -m32 exp2.o -o exp2.exe -v
clang version 8.0.0 (tags/RELEASE_800/rc1 352000)
Target: i386-pc-windows-msvc
Thread model: posix
InstalledDir: d:\clang8rc1\bin
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x86\link.exe" -out:exp2.exe "-libpath:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86" "-libpath:C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\ucrt\x86" "-libpath:C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x86" -nologo exp2.o

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 11, 2019

Checked https://reviews.llvm.org/D57625 in.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 11, 2019

Checked https://reviews.llvm.org/D57625 in.

Great, thank you! Just to double check, are you still thinking that this should not be backported to 8.0?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 11, 2019

I'll try, after broad testing happens.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 11, 2019

LLVM described the Windows runtime library incorrectly, which D49273 exposed. The runtime support, at least for math functions, was updated in D57625 and rL353758.

@zmodem
Copy link
Collaborator

zmodem commented Feb 12, 2019

I'm okay with merging r353733, but let's allow it to "bake" in trunk a little longer first.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 12, 2019

I agree. r353733 and r353758 have been in the oven for nearly 24h now. Methinks that in 12h or so they'll be done out of the baking and ready to serve. Yes?

Thank you.

@zmodem
Copy link
Collaborator

zmodem commented Feb 13, 2019

It turns out there was a lot of refactoring to these files lately.

Merged r352707, r352714, r352886, r352892, r352895, r352908, r352917, r352935, r353213, r353733, and r353758 to release_80 in r353934.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 13, 2019

Merged r352707, r352714, r352886, r352892, r352895, r352908, r352917,
r352935, r353213, r353733, and r353758 to release_80 in r353934.

Thank you.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

3 participants