summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprScalar.cpp
diff options
context:
space:
mode:
authorJinjinLi868 <lijinjin.868@bytedance.com>2024-09-10 10:47:33 +0800
committerGitHub <noreply@github.com>2024-09-10 10:47:33 +0800
commit56905dab7da50bccfcceaeb496b206ff476127e1 (patch)
treeaadeb41a88bce68d492669647e027e6fadf35e3f /clang/lib/CodeGen/CGExprScalar.cpp
parentffcff4af59712792712b33648f8ea148b299c364 (diff)
[clang] fix half && bfloat16 convert node expr codegen (#89051)
Data type conversion between fp16 and bf16 will generate fptrunc and fpextend nodes, but they are actually bitcast nodes.
Diffstat (limited to 'clang/lib/CodeGen/CGExprScalar.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 88fbbe6c4c96..9027bab6b680 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1455,6 +1455,10 @@ Value *ScalarExprEmitter::EmitScalarCast(Value *Src, QualType SrcType,
return Builder.CreateFPToUI(Src, DstTy, "conv");
}
+ if ((DstElementTy->is16bitFPTy() && SrcElementTy->is16bitFPTy())) {
+ Value *FloatVal = Builder.CreateFPExt(Src, Builder.getFloatTy(), "fpext");
+ return Builder.CreateFPTrunc(FloatVal, DstTy, "fptrunc");
+ }
if (DstElementTy->getTypeID() < SrcElementTy->getTypeID())
return Builder.CreateFPTrunc(Src, DstTy, "conv");
return Builder.CreateFPExt(Src, DstTy, "conv");