Skip to content

Commit 5437d90

Browse files
authored
[CIR] Upstream FPToFPBuiltin ATanOp (#157496)
Upstream support for FPToFPBuiltin ATanOp
1 parent 5125f47 commit 5437d90

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,6 +3837,16 @@ def CIR_ASinOp : CIR_UnaryFPToFPBuiltinOp<"asin", "ASinOp"> {
38373837
}];
38383838
}
38393839

3840+
def CIR_ATanOp : CIR_UnaryFPToFPBuiltinOp<"atan", "ATanOp"> {
3841+
let summary = "Computes the floating-point arcus tangent value";
3842+
let description = [{
3843+
`cir.atan` computes the arcus tangent of a floating-point operand
3844+
and returns a result of the same type.
3845+
3846+
Floating-point exceptions are ignored, and it does not set `errno`.
3847+
}];
3848+
}
3849+
38403850
def CIR_FAbsOp : CIR_UnaryFPToFPBuiltinOp<"fabs", "FAbsOp"> {
38413851
let summary = "Computes the floating-point absolute value";
38423852
let description = [{

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
413413
return emitUnaryFPBuiltin<cir::ACosOp>(*this, *e);
414414
case Builtin::BI__builtin_elementwise_asin:
415415
return emitUnaryFPBuiltin<cir::ASinOp>(*this, *e);
416+
case Builtin::BI__builtin_elementwise_atan:
417+
return emitUnaryFPBuiltin<cir::ATanOp>(*this, *e);
416418
}
417419

418420
// If this is an alias for a lib function (e.g. __builtin_sin), emit

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,14 @@ mlir::LogicalResult CIRToLLVMBaseClassAddrOpLowering::matchAndRewrite(
11031103
return mlir::success();
11041104
}
11051105

1106+
mlir::LogicalResult CIRToLLVMATanOpLowering::matchAndRewrite(
1107+
cir::ATanOp op, OpAdaptor adaptor,
1108+
mlir::ConversionPatternRewriter &rewriter) const {
1109+
mlir::Type resTy = typeConverter->convertType(op.getType());
1110+
rewriter.replaceOpWithNewOp<mlir::LLVM::ATanOp>(op, resTy, adaptor.getSrc());
1111+
return mlir::success();
1112+
}
1113+
11061114
mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite(
11071115
cir::AllocaOp op, OpAdaptor adaptor,
11081116
mlir::ConversionPatternRewriter &rewriter) const {
@@ -2468,6 +2476,7 @@ void ConvertCIRToLLVMPass::runOnOperation() {
24682476
CIRToLLVMAssumeSepStorageOpLowering,
24692477
CIRToLLVMAtomicCmpXchgLowering,
24702478
CIRToLLVMBaseClassAddrOpLowering,
2479+
CIRToLLVMATanOpLowering,
24712480
CIRToLLVMBinOpLowering,
24722481
CIRToLLVMBitClrsbOpLowering,
24732482
CIRToLLVMBitClzOpLowering,

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,15 @@ class CIRToLLVMASinOpLowering : public mlir::OpConversionPattern<cir::ASinOp> {
755755
mlir::ConversionPatternRewriter &) const override;
756756
};
757757

758+
class CIRToLLVMATanOpLowering : public mlir::OpConversionPattern<cir::ATanOp> {
759+
public:
760+
using mlir::OpConversionPattern<cir::ATanOp>::OpConversionPattern;
761+
762+
mlir::LogicalResult
763+
matchAndRewrite(cir::ATanOp op, OpAdaptor,
764+
mlir::ConversionPatternRewriter &) const override;
765+
};
766+
758767
class CIRToLLVMInlineAsmOpLowering
759768
: public mlir::OpConversionPattern<cir::InlineAsmOp> {
760769
mlir::DataLayout const &dataLayout;

clang/test/CIR/CodeGen/builtins-elementwise.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,30 @@ void test_builtin_elementwise_asin(float f, double d, vfloat4 vf4,
6262
// OGCG: %{{.*}} = call <4 x double> @llvm.asin.v4f64(<4 x double> %{{.*}})
6363
vd4 = __builtin_elementwise_asin(vd4);
6464
}
65+
66+
void test_builtin_elementwise_atan(float f, double d, vfloat4 vf4,
67+
vdouble4 vd4) {
68+
// CIR-LABEL: test_builtin_elementwise_atan
69+
// LLVM-LABEL: test_builtin_elementwise_atan
70+
// OGCG-LABEL: test_builtin_elementwise_atan
71+
72+
// CIR: %{{.*}} = cir.atan %{{.*}} : !cir.float
73+
// LLVM: %{{.*}} = call float @llvm.atan.f32(float %{{.*}})
74+
// OGCG: %{{.*}} = call float @llvm.atan.f32(float %{{.*}})
75+
f = __builtin_elementwise_atan(f);
76+
77+
// CIR: %{{.*}} = cir.atan %{{.*}} : !cir.double
78+
// LLVM: %{{.*}} = call double @llvm.atan.f64(double %{{.*}})
79+
// OGCG: %{{.*}} = call double @llvm.atan.f64(double %{{.*}})
80+
d = __builtin_elementwise_atan(d);
81+
82+
// CIR: %{{.*}} = cir.atan %{{.*}} : !cir.vector<4 x !cir.float>
83+
// LLVM: %{{.*}} = call <4 x float> @llvm.atan.v4f32(<4 x float> %{{.*}})
84+
// OGCG: %{{.*}} = call <4 x float> @llvm.atan.v4f32(<4 x float> %{{.*}})
85+
vf4 = __builtin_elementwise_atan(vf4);
86+
87+
// CIR: %{{.*}} = cir.atan %{{.*}} : !cir.vector<4 x !cir.double>
88+
// LLVM: %{{.*}} = call <4 x double> @llvm.atan.v4f64(<4 x double> %{{.*}})
89+
// OGCG: %{{.*}} = call <4 x double> @llvm.atan.v4f64(<4 x double> %{{.*}})
90+
vd4 = __builtin_elementwise_atan(vd4);
91+
}

0 commit comments

Comments
 (0)