Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,34 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
mlir::Value VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
llvm_unreachable("NYI");
}
mlir::Value VisitAsTypeExpr(AsTypeExpr *E) { llvm_unreachable("NYI"); }

mlir::Value VisitAsTypeExpr(AsTypeExpr *E) {
mlir::Value src = CGF.emitScalarExpr(E->getSrcExpr());
QualType qualSrcTy = E->getSrcExpr()->getType();
QualType qualDstTy = E->getType();

// Bitwidth check
unsigned srcBits = CGF.getContext().getTypeSize(qualSrcTy);
unsigned dstBits = CGF.getContext().getTypeSize(qualDstTy);
if (srcBits != dstBits) {
emitError(CGF.getLoc(E->getExprLoc()),
"source and destination must have equal bitwidths: '" +
llvm::Twine(srcBits) + "' vs '" + llvm::Twine(dstBits) +
"'");
return nullptr;
}

// No-op if already same type
mlir::Type srcTy = CGF.convertType(qualSrcTy);
mlir::Type dstTy = CGF.convertType(qualDstTy);
if (srcTy == dstTy)
return src;

// Perform the bitcast
auto loc = CGF.getLoc(E->getExprLoc());
return Builder.create<cir::CastOp>(loc, dstTy, cir::CastKind::bitcast, src);
}

mlir::Value VisitAtomicExpr(AtomicExpr *E) {
return CGF.emitAtomicExpr(E).getScalarVal();
}
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CIR/CodeGen/OpenCL/vec_int_as_float.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang -target x86_64-unknown-linux-gnu -cl-std=CL3.0 -Xclang -finclude-default-header -Xclang -fclangir -emit-cir %s -o - | FileCheck %s

float4 test(int4 in)
{
return as_float4(in); // Bit reinterpretation
}

// CHECK: [[LOAD:%.*]] = cir.load align(16) %{{.*}} : !cir.ptr<!cir.vector<!s32i x 4>>, !cir.vector<!s32i x 4>
// CHECK: %{{.*}} = cir.cast bitcast [[LOAD]] : !cir.vector<!s32i x 4> -> !cir.vector<!cir.float x 4>
Loading