[clang] 5437d90 - [CIR] Upstream FPToFPBuiltin ATanOp (#157496)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 11 09:01:16 PDT 2025
Author: Amr Hesham
Date: 2025-09-11T18:01:12+02:00
New Revision: 5437d90bb72e38ad767dd2e130d23675130a7857
URL: https://github.com/llvm/llvm-project/commit/5437d90bb72e38ad767dd2e130d23675130a7857
DIFF: https://github.com/llvm/llvm-project/commit/5437d90bb72e38ad767dd2e130d23675130a7857.diff
LOG: [CIR] Upstream FPToFPBuiltin ATanOp (#157496)
Upstream support for FPToFPBuiltin ATanOp
Added:
Modified:
clang/include/clang/CIR/Dialect/IR/CIROps.td
clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
clang/test/CIR/CodeGen/builtins-elementwise.c
Removed:
################################################################################
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index f3715bdb5ef42..b3c435cc59140 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -3837,6 +3837,16 @@ def CIR_ASinOp : CIR_UnaryFPToFPBuiltinOp<"asin", "ASinOp"> {
}];
}
+def CIR_ATanOp : CIR_UnaryFPToFPBuiltinOp<"atan", "ATanOp"> {
+ let summary = "Computes the floating-point arcus tangent value";
+ let description = [{
+ `cir.atan` computes the arcus tangent 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 = [{
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 2150a810e269d..8892e62accb74 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -413,6 +413,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
return emitUnaryFPBuiltin<cir::ACosOp>(*this, *e);
case Builtin::BI__builtin_elementwise_asin:
return emitUnaryFPBuiltin<cir::ASinOp>(*this, *e);
+ case Builtin::BI__builtin_elementwise_atan:
+ return emitUnaryFPBuiltin<cir::ATanOp>(*this, *e);
}
// If this is an alias for a lib function (e.g. __builtin_sin), emit
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 816987ba48145..d9097b0b9e03d 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1103,6 +1103,14 @@ mlir::LogicalResult CIRToLLVMBaseClassAddrOpLowering::matchAndRewrite(
return mlir::success();
}
+mlir::LogicalResult CIRToLLVMATanOpLowering::matchAndRewrite(
+ cir::ATanOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ mlir::Type resTy = typeConverter->convertType(op.getType());
+ rewriter.replaceOpWithNewOp<mlir::LLVM::ATanOp>(op, resTy, adaptor.getSrc());
+ return mlir::success();
+}
+
mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite(
cir::AllocaOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
@@ -2468,6 +2476,7 @@ void ConvertCIRToLLVMPass::runOnOperation() {
CIRToLLVMAssumeSepStorageOpLowering,
CIRToLLVMAtomicCmpXchgLowering,
CIRToLLVMBaseClassAddrOpLowering,
+ CIRToLLVMATanOpLowering,
CIRToLLVMBinOpLowering,
CIRToLLVMBitClrsbOpLowering,
CIRToLLVMBitClzOpLowering,
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
index 34b121c88f677..dd1dd0aaec7d8 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
@@ -755,6 +755,15 @@ class CIRToLLVMASinOpLowering : public mlir::OpConversionPattern<cir::ASinOp> {
mlir::ConversionPatternRewriter &) const override;
};
+class CIRToLLVMATanOpLowering : public mlir::OpConversionPattern<cir::ATanOp> {
+public:
+ using mlir::OpConversionPattern<cir::ATanOp>::OpConversionPattern;
+
+ mlir::LogicalResult
+ matchAndRewrite(cir::ATanOp op, OpAdaptor,
+ mlir::ConversionPatternRewriter &) const override;
+};
+
class CIRToLLVMInlineAsmOpLowering
: public mlir::OpConversionPattern<cir::InlineAsmOp> {
mlir::DataLayout const &dataLayout;
diff --git a/clang/test/CIR/CodeGen/builtins-elementwise.c b/clang/test/CIR/CodeGen/builtins-elementwise.c
index 431558d7e9697..e3460f06d166a 100644
--- a/clang/test/CIR/CodeGen/builtins-elementwise.c
+++ b/clang/test/CIR/CodeGen/builtins-elementwise.c
@@ -62,3 +62,30 @@ void test_builtin_elementwise_asin(float f, double d, vfloat4 vf4,
// OGCG: %{{.*}} = call <4 x double> @llvm.asin.v4f64(<4 x double> %{{.*}})
vd4 = __builtin_elementwise_asin(vd4);
}
+
+void test_builtin_elementwise_atan(float f, double d, vfloat4 vf4,
+ vdouble4 vd4) {
+ // CIR-LABEL: test_builtin_elementwise_atan
+ // LLVM-LABEL: test_builtin_elementwise_atan
+ // OGCG-LABEL: test_builtin_elementwise_atan
+
+ // CIR: %{{.*}} = cir.atan %{{.*}} : !cir.float
+ // LLVM: %{{.*}} = call float @llvm.atan.f32(float %{{.*}})
+ // OGCG: %{{.*}} = call float @llvm.atan.f32(float %{{.*}})
+ f = __builtin_elementwise_atan(f);
+
+ // CIR: %{{.*}} = cir.atan %{{.*}} : !cir.double
+ // LLVM: %{{.*}} = call double @llvm.atan.f64(double %{{.*}})
+ // OGCG: %{{.*}} = call double @llvm.atan.f64(double %{{.*}})
+ d = __builtin_elementwise_atan(d);
+
+ // CIR: %{{.*}} = cir.atan %{{.*}} : !cir.vector<4 x !cir.float>
+ // LLVM: %{{.*}} = call <4 x float> @llvm.atan.v4f32(<4 x float> %{{.*}})
+ // OGCG: %{{.*}} = call <4 x float> @llvm.atan.v4f32(<4 x float> %{{.*}})
+ vf4 = __builtin_elementwise_atan(vf4);
+
+ // CIR: %{{.*}} = cir.atan %{{.*}} : !cir.vector<4 x !cir.double>
+ // LLVM: %{{.*}} = call <4 x double> @llvm.atan.v4f64(<4 x double> %{{.*}})
+ // OGCG: %{{.*}} = call <4 x double> @llvm.atan.v4f64(<4 x double> %{{.*}})
+ vd4 = __builtin_elementwise_atan(vd4);
+}
More information about the cfe-commits
mailing list