[clang] [CIR] Upstream lowering of conditional operators to TernaryOp (PR #138156)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 09:01:36 PDT 2025
================
@@ -272,6 +272,22 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return createCast(loc, cir::CastKind::bitcast, src, newTy);
}
+ // TODO(cir): the following function was introduced to keep in sync with LLVM
+ // codegen. CIR does not have "zext" operations. It should eventually be
+ // renamed or removed. For now, we just add whatever cast is required here.
+ mlir::Value createZExtOrBitCast(mlir::Location loc, mlir::Value src,
+ mlir::Type newTy) {
+ mlir::Type srcTy = src.getType();
+
+ if (srcTy == newTy)
+ return src;
+
+ if (mlir::isa<cir::BoolType>(srcTy) && mlir::isa<cir::IntType>(newTy))
+ return createBoolToInt(src, newTy);
+
+ llvm_unreachable("unhandled extension cast");
----------------
erichkeane wrote:
This doesn't seem like it should be an unreachable, right? Perhaps an assert that the types are equal or its int-to-bool, but this unreachable seems odd? also, what function in classic-codegen is this intended to mirror? The only one I found was the `CastInst` one by the same name, and it doesn't seem to mirror its implementation much at all.
https://github.com/llvm/llvm-project/pull/138156
More information about the cfe-commits
mailing list