Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -4612,6 +4612,16 @@ def CIR_ExpOp : CIR_UnaryFPToFPBuiltinOp<"exp", "ExpOp"> {
}];
}

def CIR_Exp2Op : CIR_UnaryFPToFPBuiltinOp<"exp2", "Exp2Op"> {
let summary = "Computes the floating-point base-2 exponential value";
let description = [{
`cir.exp2` computes the base-2 exponential of a floating-point operand and
returns a result of the same type.

Floating-point exceptions are ignored, and it does not set `errno`.
}];
}

def CIR_FAbsOp : CIR_UnaryFPToFPBuiltinOp<"fabs", "FAbsOp"> {
let summary = "Computes the floating-point absolute value";
let description = [{
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,17 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
assert(!cir::MissingFeatures::fastMathFlags());
return emitUnaryMaybeConstrainedFPBuiltin<cir::ExpOp>(*this, *e);

case Builtin::BIexp2:
case Builtin::BIexp2f:
case Builtin::BIexp2l:
case Builtin::BI__builtin_exp2:
case Builtin::BI__builtin_exp2f:
case Builtin::BI__builtin_exp2f16:
case Builtin::BI__builtin_exp2l:
case Builtin::BI__builtin_exp2f128:
assert(!cir::MissingFeatures::fastMathFlags());
return emitUnaryMaybeConstrainedFPBuiltin<cir::Exp2Op>(*this, *e);

case Builtin::BIfabs:
case Builtin::BIfabsf:
case Builtin::BIfabsl:
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ mlir::LogicalResult CIRToLLVMExpOpLowering::matchAndRewrite(
return mlir::success();
}

mlir::LogicalResult CIRToLLVMExp2OpLowering::matchAndRewrite(
cir::Exp2Op op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::Type resTy = typeConverter->convertType(op.getType());
rewriter.replaceOpWithNewOp<mlir::LLVM::Exp2Op>(op, resTy, adaptor.getSrc());
return mlir::success();
}

static mlir::Value getLLVMIntCast(mlir::ConversionPatternRewriter &rewriter,
mlir::Value llvmSrc, mlir::Type llvmDstIntTy,
bool isUnsigned, uint64_t cirSrcWidth,
Expand Down
21 changes: 21 additions & 0 deletions clang/test/CIR/CodeGen/builtins-floating-point.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,24 @@ long double expl(long double f) {
// LLVM: %{{.*}} = call fp128 @llvm.exp.f128(fp128 %{{.*}})
// OGCG: %{{.*}} = call fp128 @llvm.exp.f128(fp128 %{{.*}})
}

float exp2f(float f) {
return __builtin_exp2f(f);
// CIR: %{{.*}} = cir.exp2 {{.*}} : !cir.float
// LLVM: %{{.*}} = call float @llvm.exp2.f32(float %{{.*}})
// OGCG: %{{.*}} = call float @llvm.exp2.f32(float %{{.*}})
}

double my_exp2(double f) {
return __builtin_exp2(f);
// CIR: %{{.*}} = cir.exp2 {{.*}} : !cir.double
// LLVM: %{{.*}} = call double @llvm.exp2.f64(double %{{.*}})
// OGCG: %{{.*}} = call double @llvm.exp2.f64(double %{{.*}})
}

long double my_exp2l(long double f) {
return __builtin_exp2l(f);
// CIR: %{{.*}} = cir.exp2 {{.*}} : !cir.long_double<!cir.f128>
// LLVM: %{{.*}} = call fp128 @llvm.exp2.f128(fp128 %{{.*}})
// OGCG: %{{.*}} = call fp128 @llvm.exp2.f128(fp128 %{{.*}})
}