[LLVMbugs] [Bug 132] [C/C++] Complex division is not supported by the frontends

bugzilla-daemon at zion.cs.uiuc.edu bugzilla-daemon at zion.cs.uiuc.edu
Thu Nov 20 11:28:37 PST 2003


http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=132

sabre at nondot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From sabre at nondot.org  2003-11-20 13:28 -------
Fixed.

Testcase: CFrontend/2003-11-20-ComplexDivision.c

Patch:
$ diff -u llvm-expand.c~ llvm-expand.c
--- llvm-expand.c~      2003-11-20 12:59:12.000000000 -0600
+++ llvm-expand.c       2003-11-20 13:25:53.000000000 -0600
@@ -4966,15 +4966,34 @@
     ResultI = append_inst(Fn, create_binary_inst("tmp", O_Add, Tmp1, Tmp2));
     break;
   }
-
-  /*case DIV_EXPR:*/  /* (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) +
i((bc-ad)/(cc+dd)) */
-
+  case RDIV_EXPR:{/* (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) */
+    llvm_value *Tmp1 =  /* a*c */
+      append_inst(Fn, create_binary_inst("tmp", O_Mul, Op0r, Op1r));
+    llvm_value *Tmp2 =  /* b*d */
+      append_inst(Fn, create_binary_inst("tmp", O_Mul, Op0i, Op1i));
+    llvm_value *Tmp3 =  /* ac+bd */
+      append_inst(Fn, create_binary_inst("tmp", O_Add, Tmp1, Tmp2));
+    llvm_value *Tmp4 =  /* c*c */
+      append_inst(Fn, create_binary_inst("tmp", O_Mul, Op1r, Op1r));
+    llvm_value *Tmp5 =  /* d*d */
+      append_inst(Fn, create_binary_inst("tmp", O_Mul, Op1i, Op1i));
+    llvm_value *Tmp6 =  /* cc+dd */
+      append_inst(Fn, create_binary_inst("tmp", O_Add, Tmp4, Tmp5));
+    ResultR = append_inst(Fn, create_binary_inst("tmp", O_Div, Tmp3, Tmp6));
+
+    Tmp1 = append_inst(Fn, create_binary_inst("tmp", O_Mul, Op0i, Op1r)); /*bc*/
+    Tmp2 = append_inst(Fn, create_binary_inst("tmp", O_Mul, Op0r, Op1i)); /*ad*/
+    Tmp3 = append_inst(Fn, create_binary_inst("tmp", O_Sub, Tmp1, Tmp2));
+    ResultR = append_inst(Fn, create_binary_inst("tmp", O_Div, Tmp3, Tmp6));
+    break;
+  }
   default:
     debug_tree(exp);
     assert(0 && "Unknown complex expression!");
   }
 
-  InitializeComplex(Fn, DestLoc, ResultR, ResultI, 0);
+  if (DestLoc)
+    InitializeComplex(Fn, DestLoc, ResultR, ResultI, 0);
 }
 
 /* llvm_expand_expr: generate code for computing expression EXP.  If the




------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the llvm-bugs mailing list