reimplement complex mul
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41226 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGComplexExpr.cpp b/CodeGen/CGComplexExpr.cpp
index a6e6c06..8c93ca3 100644
--- a/CodeGen/CGComplexExpr.cpp
+++ b/CodeGen/CGComplexExpr.cpp
@@ -68,6 +68,7 @@
// case Expr::CastExprClass:
// case Expr::CallExprClass:
ComplexPairTy VisitBinaryOperator(const BinaryOperator *BO);
+ ComplexPairTy VisitBinMul (const BinaryOperator *E);
ComplexPairTy VisitBinAdd (const BinaryOperator *E);
ComplexPairTy VisitBinAssign (const BinaryOperator *E);
@@ -231,7 +232,6 @@
}
ComplexPairTy ComplexExprEmitter::VisitBinAdd(const BinaryOperator *E) {
- // This must be a complex number.
ComplexPairTy LHS = Visit(E->getLHS());
ComplexPairTy RHS = Visit(E->getRHS());
@@ -241,6 +241,21 @@
return ComplexPairTy(ResR, ResI);
}
+ComplexPairTy ComplexExprEmitter::VisitBinMul(const BinaryOperator *E) {
+ ComplexPairTy LHS = Visit(E->getLHS());
+ ComplexPairTy RHS = Visit(E->getRHS());
+
+ llvm::Value *ResRl = CGF.Builder.CreateMul(LHS.first, RHS.first, "mul.rl");
+ llvm::Value *ResRr = CGF.Builder.CreateMul(LHS.second, RHS.second, "mul.rr");
+ llvm::Value *ResR = CGF.Builder.CreateSub(ResRl, ResRr, "mul.r");
+
+ llvm::Value *ResIl = CGF.Builder.CreateMul(LHS.second, RHS.first, "mul.il");
+ llvm::Value *ResIr = CGF.Builder.CreateMul(LHS.first, RHS.second, "mul.ir");
+ llvm::Value *ResI = CGF.Builder.CreateAdd(ResIl, ResIr, "mul.i");
+
+ return ComplexPairTy(ResR, ResI);
+}
+
ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
assert(E->getLHS()->getType().getCanonicalType() ==
E->getRHS()->getType().getCanonicalType() && "Invalid assignment");