First Last Prev Next    No search results available
Details
: [llvmgcc] Complex division is not supported
Bug#: 132
: tools
: llvm-gcc
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: normal
: 1.1

:
: compile-fail
:
:
  Show dependency tree - Show dependency graph
People
Reporter: Chris Lattner <sabre@nondot.org>
Assigned To: Chris Lattner <sabre@nondot.org>

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2003-11-19 12:12
This testcase:
---
int test() {
  __complex__ double C;
  double D;
  C / D;
}
---

Spews:
 <rdiv_expr 0x400212b8
    type <complex_type 0x40020c40 complex double
        type <real_type 0x40020a80 double DF
            size <integer_cst 0x4001b5c8 constant 64>
            unit size <integer_cst 0x4001b7bc constant 8>
            align 32 symtab 0 alias set -1 precision 64
            pointer_to_this <pointer_type 0x40229d20>>
        DC
        size <integer_cst 0x4001b94c constant 128>
        unit size <integer_cst 0x4001b974 constant 16>
        align 32 symtab 0 alias set -1>
   
    arg 0 <var_decl 0x40246d90 C type <complex_type 0x40020c40 complex double>
        used DC file test.c line 4 size <integer_cst 0x4001b94c 128> unit size
<integer_cst 0x4001b974 16>
        align 128 context <function_decl 0x40246bd0 test>
        chain <var_decl 0x40246e00 D type <real_type 0x40020a80 double>
            used DF file test.c line 5 size <integer_cst 0x4001b5c8 64> unit
size <integer_cst 0x4001b7bc 8>
            align 64 context <function_decl 0x40246bd0 test>>>
    arg 1 <complex_expr 0x400212a0 type <complex_type 0x40020c40 complex double>
        arg 0 <var_decl 0x40246e00 D>
        arg 1 <real_cst 0x40018400 type <real_type 0x40020a80 double>
            constant 0.0>>>
cc1: ../../gcc-3.4/gcc/llvm-expand.c:4975: llvm_expand_complex_binary_expr:
Assertion `0 && "Unknown complex expression!"' failed.

-Chris
------- Comment #1 From Chris Lattner 2003-11-20 13:28:37 -------
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

First Last Prev Next    No search results available