-
Notifications
You must be signed in to change notification settings - Fork 84
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
[CIR][Fix] FP builtins should lower directly to LLVM builtins #670
base: main
Are you sure you want to change the base?
Conversation
Let me illustrate more background here so the motivation of this change can be made clearer. Consider the following code: double test(double x) {
return __builtin_cos(x);
} Compile it w/o clangir and we get: define dso_local double @test(double noundef %x) {
entry:
;; ...
%call = call double @cos(double noundef %0) #3
;; ...
} This is why the two patches mentioned above decide to convert those FP builtins to libc calls during lowering prepare. But if you do some debugging work you'll find that So converting |
Nice catch! |
Sounds like the previous approach still works for |
Do you mean we should assert for |
445957e
to
e17e313
Compare
Rebased onto the latest |
What I mean is that there's clearly a path that's now emitting wrong code and nothing is being done about it, please prevent that from happening as part of this PR, otherwise it might become technical debt - I suggest you add assertions or just add the proper hooks/support (so you don't need to delete a bunch of useful code you already added) |
LLVM lowering for the following operations is introduced in llvm#616 and llvm#651: cos, exp, exp2, log, log10, log2, sin, sqrt, fmod, and pow. However, they are not lowered to their corresponding LLVM intrinsics; instead they are transformed to libc calls during lowering prepare. This does not match the upstream behavior. This patch tries to correct this mistake.
e17e313
to
f47ab9e
Compare
Rebased onto the latest |
LLVM lowering for the following operations is introduced in #616 and #651:
cos
,exp
,exp2
,log
,log10
,log2
,sin
,sqrt
,fmod
, andpow
. However, they are not lowered to their corresponding LLVM intrinsics; instead they are transformed to libc calls during lowering prepare. This does not match the upstream behavior.This PR tries to correct this mistake. It makes all CIR FP intrinsic ops lower to their corresponding LLVM intrinsics (
fmod
is a special case and it is lowered to thefrem
LLVM instruction).