Hi,

The attached patch is a proposed fix for bug# 763. The failing example and 
description of the problem and fix are attached here and also to the bug report.
Can a gatekeeper please review the fix?

Thanks.
-Pallavi

Attachment: fix763.p
Description: fix763.p

$ cat sample.c
typedef struct S1 {
  float f[2];
} S1;
S1 operator/ (S1 a, float b)  { }
struct S2 {
  void copy(const S2& v) {
    for (int i = 0; i < 10; i++)
      t[i] = v[i];
  }
  S1 operator[](int index) const {
    return t[index];
  }
  void div(const S2& a, float& b) {
    for (int i = 0; i < 10; i++)
      t[i] = a.t[i] / b;
  }
  S1 t[10];
};

class C1 {
 public:
  const C1& operator=(const C1& c) {
    S2& t = (*this).s;
    t.copy(c.s);
  }
  S2 s;
};

C1 operator/(C1& a, float& b) {
  C1 c;
  (c.s).div(a.s, b);
  return c;
}
class C2 {
  C1 temp1;
  void func1();
};
void C2::func1(){
  float f2;
  temp1 = temp1/f2;
}
$ openCC -c -O3 sample.c 

### Assertion failure at line 2344 of ...osprey/be/opt/opt_htable.cxx:
### Compiler Error in file sample.c during Global Optimization -- Create 
CODEMAP Representation phase:
### CODEMAP::Add_def: dtyp and dsctyp mismatch.
openCC INTERNAL ERROR: ...lib/gcc-lib/x86_64-open64-linux/4.2/be returned 
non-zero status 1
Problem:
Coderep creation encounters the following WN:
0x80f6838:    F4F4LDID 55 <1,10,.preg_F4> T<10,.predef_F4,4> # anon4_1
0x80f6458:   MSTID 0 <2,29,rr> T<56,S1,4> {line: 0/0}

which causes the following assertion to fail in opt_htable.cxx:
// Create a new coderep node for this new variable version in the htable
CODEREP *
CODEMAP::Add_def(...) {
...
  if (MTYPE_is_float(dtyp)) {
    FmtAssert(MTYPE_is_float(dsctyp) && MTYPE_size_min(dtyp) == 
MTYPE_size_min(dsctyp),
              ("CODEMAP::Add_def: dtyp and dsctyp mismatch."));
  }
...
}

where, the dtyp corresponds to the rtype of the kid (MTYPE_F4)
and dsctyp corresponds to the desc type of the parent (MTYPE_M).

The whirl node shown above results from array scalarization involving the 
following nodes:
###Say the following represents A[i] = x:
0x80f5f38:    F4F4LDID 0 <2,58,rr> T<10,.predef_F4,4>
0x80f5f78:     U8LDA 0 <2,6,anon4> T<58,anon_ptr.,8>
0x80f5f98:     U4INTCONST 10 (0xa)
0x80f5fb8:      I4I4LDID 50 <1,4,.preg_I4> T<4,.predef_I4,4> # i
0x80f5fd8:     I8I4CVT
0x80f5f58:    U8ARRAY 1 8
0x80f6008:   F4ISTORE 0 T<59,anon_ptr.,8> {line: 1/15}
...
###Array scalarization detects use of A[i] say y = A[i]
0x80f63a8:      U8LDA 0 <2,6,anon4> T<58,anon_ptr.,8>
0x80f63c8:      U4INTCONST 10 (0xa)
0x80f63e8:       I4I4LDID 51 <1,4,.preg_I4> T<4,.predef_I4,4> # i
0x80f6408:      I8I4CVT
0x80f6388:     U8ARRAY 1 8
0x80f6428:    MMILOAD 0 T<56,S1,4,C> T<69,anon_ptr.,8>
0x80f6458:   MSTID 0 <2,29,rr> T<56,S1,4> {line: 0/0}

###New node is created to represent preg = x
0x80f5f38:     F4F4LDID 0 <2,58,rr> T<10,.predef_F4,4>
0x80f6738:    F4PAREN
0x80f6a18:   F4STID 55 <1,10,.preg_F4> T<10,.predef_F4,4> # anon4_1 {line: 1/15}
...
###Definition of A[i] is replaced by A[i] = preg
0x80f61e8:    F4F4LDID 55 <1,10,.preg_F4> T<10,.predef_F4,4> # anon4_1
0x80f5f78:     U8LDA 0 <2,6,anon4> T<58,anon_ptr.,8>
0x80f5f98:     U4INTCONST 10 (0xa)
0x80f5fb8:      I4I4LDID 53 <1,4,.preg_I4> T<4,.predef_I4,4> # _i_0
0x80f5fd8:     I8I4CVT
0x80f5f58:    U8ARRAY 1 8
0x80f6008:   F4ISTORE 0 T<59,anon_ptr.,8> {line: 1/15}
...
###Use of A[i] is replaced by y = preg, leading to the problematic Whirl node.
0x80f6838:    F4F4LDID 55 <1,10,.preg_F4> T<10,.predef_F4,4> # anon4_1
0x80f6458:   MSTID 0 <2,29,rr> T<56,S1,4> {line: 0/0}

At the beginning of function 'Process_Store' in sclrze.cxx, a check is done to 
avoid scalarizing MTYPE_M stores.
However, the above example passes through the check because the definition does 
not involve MTYPE_M but the use
(obtained from following the edges of dependence graph) does. 

Solution:
Detect MTYPE_M in use of array and do not scalarize if present.
------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes
not days. Key insights are discussed in the 2010 Forrester Wave Report as
part of an in-depth evaluation of disaster recovery service providers.
Forrester found the best-in-class provider in terms of services and vision.
Read this report now!  http://p.sf.net/sfu/ibm-webcastpromo
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to