-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
[Clang][CodeGen] Loose the cast check when emitting builtins #81669
Conversation
This patch looses the cast check (`canLosslesslyBitCastTo`) and leaves it to the one inside `CreateBitCast`. It seems too conservative for the use case here.
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Shilei Tian (shiltian) ChangesThis patch looses the cast check ( Full diff: https://github.com/llvm/llvm-project/pull/81669.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ee0b7504769622..9bc60466d09be6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5912,8 +5912,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
}
}
- assert(ArgValue->getType()->canLosslesslyBitCastTo(PTy) &&
- "Must be able to losslessly bit cast to param");
// Cast vector type (e.g., v256i32) to x86_amx, this only happen
// in amx intrinsics.
if (PTy->isX86_AMXTy())
@@ -5943,8 +5941,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
}
}
- assert(V->getType()->canLosslesslyBitCastTo(RetTy) &&
- "Must be able to losslessly bit cast result type");
// Cast x86_amx to vector type (e.g., v256i32), this only happen
// in amx intrinsics.
if (V->getType()->isX86_AMXTy())
|
I can't tell what you're trying to fix here. Is this fixing a crash? Or is the check redundant? Or is it necessary for some followup change you want to make? |
Sorry, I should have clearly mentioned that. Yes, it is for my followup change #80908. In #80908, we changed the type of LLVM builtin but kept the corresponding clang builtin unchanged to avoid breaking existing uses. Specifically, the original builtin accepts some |
Don't see how that could be related; you can losslessly bitconvert between i16 and bfloat |
I guess it's an oversight from that function to not allow FP <-> INT casts when they have the same width? I think the right fix is teaching that function about FP <-> INT casts. |
The documentation for that function says:
A cast between float and int sounds like "re-interpretation of the bits" to me. Though the function already allows it if it's a vector of int/float. TBH I don't really understand what the purpose of this function is. One of the main uses seems to be to restrict what the For the purposes of this specific change, I think that just dropping the assert is indeed the right thing to do. The cast in the bitcast itself is sufficient. |
Yes,
Yeah. I was reluctant to allow it in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(It feels a little weird that the types in the clang AST don't actually match the LLVM builtin, but I guess it's not likely to actually cause any issues.)
This patch looses the cast check (
canLosslesslyBitCastTo
) and leaves it to theone inside
CreateBitCast
. It seems too conservative for the use case here.