-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CIR] Upstream DivOp for ComplexType #153796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6613d4c
6879b70
fc62a60
511115f
6745410
a9a9fca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2966,7 +2966,7 @@ def CIR_ComplexSubOp : CIR_Op<"complex.sub", [ | |||||
| } | ||||||
|
|
||||||
| //===----------------------------------------------------------------------===// | ||||||
| // ComplexMulOp | ||||||
| // ComplexMulOp & ComplexDivOp | ||||||
| //===----------------------------------------------------------------------===// | ||||||
|
|
||||||
| def CIR_ComplexRangeKind : CIR_I32EnumAttr< | ||||||
|
|
@@ -3013,6 +3013,44 @@ def CIR_ComplexMulOp : CIR_Op<"complex.mul", [ | |||||
| }]; | ||||||
| } | ||||||
|
|
||||||
| def CIR_ComplexDivOp : CIR_Op<"complex.div", [ | ||||||
| Pure, SameOperandsAndResultType | ||||||
| ]> { | ||||||
| let summary = "Complex division"; | ||||||
| let description = [{ | ||||||
| The `cir.complex.div` operation takes two complex numbers and returns | ||||||
| their division. | ||||||
|
|
||||||
| Range is used to select the implementation used when the operation | ||||||
|
||||||
| Range is used to select the implementation used when the operation | |
| The `range` attribute is used to select the algorithm used when the operation |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. For 'promoted' the values are promoted to a higher precision type, if possible, and the calculation is performed using the algebraic formula. We only fall back on Smith's algorithm when the target does not support a higher precision type. Also, this only applies to floating-point types. This description should mention that for integer-based complex values the algebraic formula is always used and 'range' is ignored.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also mention that no special handling for NaN values is used with 'improved' or 'promoted'.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this here in addition to $range?
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ namespace { | |||||
| class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { | ||||||
| CIRGenFunction &cgf; | ||||||
| CIRGenBuilderTy &builder; | ||||||
| bool fpHasBeenPromoted = false; | ||||||
|
|
||||||
| public: | ||||||
| explicit ComplexExprEmitter(CIRGenFunction &cgf) | ||||||
|
|
@@ -128,15 +129,43 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { | |||||
| mlir::Value emitBinAdd(const BinOpInfo &op); | ||||||
| mlir::Value emitBinSub(const BinOpInfo &op); | ||||||
| mlir::Value emitBinMul(const BinOpInfo &op); | ||||||
| mlir::Value emitBinDiv(const BinOpInfo &op); | ||||||
|
|
||||||
| QualType higherPrecisionTypeForComplexArithmetic(QualType elementType, | ||||||
| bool isDivOpCode) { | ||||||
| ASTContext &astContext = cgf.getContext(); | ||||||
| const QualType higherElementType = | ||||||
| astContext.GetHigherPrecisionFPType(elementType); | ||||||
| const llvm::fltSemantics &elementTypeSemantics = | ||||||
| astContext.getFloatTypeSemantics(elementType); | ||||||
| const llvm::fltSemantics &higherElementTypeSemantics = | ||||||
| astContext.getFloatTypeSemantics(higherElementType); | ||||||
|
|
||||||
| // Check that the promoted type can handle the intermediate values without | ||||||
| // overflowing. This can be interpreted as: | ||||||
| // (SmallerType.LargestFiniteVal * SmallerType.LargestFiniteVal) * 2 <= | ||||||
| // LargerType.LargestFiniteVal. | ||||||
|
||||||
| // LargerType.LargestFiniteVal. | |
| // LargerType.LargestFiniteVal. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be deferred until lowering. There is no reason to promote the type in the initial CIR representation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will defer that to lower preparation and make the condition depend on mlir::Type, not QualType (Not available in LoweringPrepare)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cgf.cgm.errorNYI("ComplexExprEmitter::emitBinMu between Complex & Scalar"); | |
| cgf.cgm.errorNYI("ComplexExprEmitter::emitBinDiv between Complex & Scalar"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.