Author: pallavimathew
Date: 2011-04-21 19:43:17 -0400 (Thu, 21 Apr 2011)
New Revision: 3566

Modified:
   trunk/osprey/be/opt/opt_etable.cxx
   trunk/osprey/be/opt/opt_etable.h
   trunk/osprey/be/opt/opt_vn.cxx
   trunk/osprey/be/opt/opt_vn_expr.cxx
   trunk/osprey/be/opt/opt_vn_expr.h
   trunk/osprey/be/opt/opt_vn_expr_taxonomy.h
   trunk/osprey/be/opt/opt_vnfre.cxx
Log:
This patch fixes a bug in GVN which was not able to differentiate scalar and 
vector constant. For example, 2.1 and <2.1, 2.1> would get the same 
value number and this bug could cause run time as well compile-time problems.

Approved by Sun Chan.


Modified: trunk/osprey/be/opt/opt_etable.cxx
===================================================================
--- trunk/osprey/be/opt/opt_etable.cxx  2011-04-20 08:20:21 UTC (rev 3565)
+++ trunk/osprey/be/opt/opt_etable.cxx  2011-04-21 23:43:17 UTC (rev 3566)
@@ -70,6 +70,7 @@
 #include "defs.h"
 #include "cxx_memory.h"
 #include "glob.h"       // for Cur_PU_Name
+#include "const.h"      // for New_Const_Sym
 
 #include "opt_base.h"
 #include "opt_bb.h"
@@ -3301,6 +3302,12 @@
    CODEREP         *_cr;
    TCON             _tcon;
 
+   // If the occurrence is a vectorized constant (all the elements should hold 
+   // same value), <_vect_ty> indicate the vect type, and the value of 
+   // elements are held by _tcon.
+   //
+   TYPE_ID _vect_ty;
+
    CODEREP *_replace_by_cr(CODEREP *x)
    {
       // Replace "x" by "_cr". Adjust usecnts.
@@ -3326,7 +3333,7 @@
       return replacement;
    }
 
-   CODEREP *_replace_by_const(CODEMAP *htable, CODEREP *x)
+   CODEREP *_replace_by_scalar_const(CODEMAP *htable, CODEREP *x)
    {
       // Create a CODEREP corresponding to the TCON and the result-type
       // of "x", and return it. Adjust usecnts.
@@ -3349,6 +3356,42 @@
       tcon_cr->IncUsecnt();
       return tcon_cr;
    }
+
+   CODEREP *_replace_by_vect_const(CODEMAP *htable, CODEREP *x)
+   {
+      // step 1: derive element type from vector type
+      //
+      TYPE_ID elem_ty = Mtype_vector_elemtype (_vect_ty);
+
+      Is_True (MTYPE_byte_size (_vect_ty) == MTYPE_byte_size(x->Dtyp()),
+               ("discrepance in vector type"));
+        
+      // step 2: generate a symbol for the constant value.
+      //
+      ST* sym;
+      sym = New_Const_Sym (Enter_tcon (_tcon), Be_Type_Tbl (TCON_ty(_tcon)));
+    
+      // step 3: generate the const vector
+      //
+      CODEREP* cr = Alloc_stack_cr (0);
+      cr->Init_rconst (_vect_ty, sym);
+      cr = htable->Hash_Rconst(cr);
+
+      // step 4: get rid of the orignial expr
+      //
+      x->DecUsecnt_rec();
+
+      return cr;
+   }
+
+   CODEREP *_replace_by_const(CODEMAP *htable, CODEREP *x)
+   {
+      if (_vect_ty == MTYPE_UNKNOWN) {
+        return _replace_by_scalar_const (htable, x);
+      }
+
+      return _replace_by_vect_const (htable, x);
+   }
    
 public:
 
@@ -3358,10 +3401,12 @@
       _kind = (type_conv? REPL_BY_TYPED_CR : REPL_BY_CR);
    }
    
-   OCCUR_REPLACEMENT(TCON replace_by_tcon):
+   OCCUR_REPLACEMENT(TCON replace_by_tcon, TYPE_ID vect_ty):
       _tcon(replace_by_tcon), 
       _kind(REPL_BY_CONST)
-   {}
+   {
+     _vect_ty = vect_ty;
+   }
    
    CODEREP *apply(CODEMAP    *htable,
                  ETABLE     *etable,
@@ -3885,11 +3930,11 @@
 // and the tree containing it needs to be rehashed.
 // =====================================================================
 void
-ETABLE::Replace_by_const(EXP_OCCURS *occur, TCON tcon)
+ETABLE::Replace_by_const(EXP_OCCURS *occur, TCON tcon, TYPE_ID vect_ty)
 {
   // Top level routine, traversing down from statement level.
   //
-  OCCUR_REPLACEMENT repl(tcon);
+  OCCUR_REPLACEMENT repl(tcon, vect_ty);
   Replace_occurs(occur, &repl);
 }
 

Modified: trunk/osprey/be/opt/opt_etable.h
===================================================================
--- trunk/osprey/be/opt/opt_etable.h    2011-04-20 08:20:21 UTC (rev 3565)
+++ trunk/osprey/be/opt/opt_etable.h    2011-04-21 23:43:17 UTC (rev 3566)
@@ -2104,7 +2104,7 @@
                                        STMTREP *old_stmt);
 
   void                   Replace_by_temp(EXP_OCCURS *occur, CODEREP *tempcr);
-  void                   Replace_by_const(EXP_OCCURS *occur, TCON tcon);
+  void                   Replace_by_const(EXP_OCCURS *occur, TCON tcon, 
TYPE_ID vect_ty);
 
   // Always use Rehash_exp() instead of Htable()->rehash() for an etable.
   CODEREP        *Rehash_exp(CODEREP *cr, UINT32 gvn, BOOL canon=TRUE) const;

Modified: trunk/osprey/be/opt/opt_vn.cxx
===================================================================
--- trunk/osprey/be/opt/opt_vn.cxx      2011-04-20 08:20:21 UTC (rev 3565)
+++ trunk/osprey/be/opt/opt_vn.cxx      2011-04-21 23:43:17 UTC (rev 3566)
@@ -136,8 +136,8 @@
 #include "opt_cvtl_rule.h"
 
 #include "opt_vn.h"
+#include "opt_vn_expr_taxonomy.h"
 
-
 // Number of predefined value numbers for integer literals.
 //
 #define VN_MAX_PREDEFINED_INT 32
@@ -292,7 +292,7 @@
    for (INT64 literal = 0; literal <= VN_MAX_PREDEFINED_INT; literal++)
    {
       const TCON         tc = Host_To_Targ(MTYPE_I8, literal);
-      const VN_EXPR::PTR expr = VN_EXPR::Create_Literal(tc);
+      const VN_EXPR::PTR expr = VN_EXPR::Create_Literal(tc, MTYPE_UNKNOWN);
 
       _vn_to_expr.set_map(_next_valnum, expr);
       _next_valnum = VN_VALNUM::Next(_next_valnum);
@@ -337,7 +337,7 @@
       //
       const MTYPE                    mty = (is_signed? MTYPE_I8 : MTYPE_U8);
       const TCON                     tc = Host_To_Targ(mty, literal);
-      const VN_EXPR::PTR             expr = VN_EXPR::Create_Literal(tc);
+      const VN_EXPR::PTR             expr = VN_EXPR::Create_Literal(tc, 
MTYPE_UNKNOWN);
       const VN_HASHTAB::EXPR_MAPPING map = 
         _status.expr_to_vn->lookup_or_insert(expr, _next_valnum);
 
@@ -403,10 +403,8 @@
            "in VN::_valnum_vn_expr()", (INT32)exprid));
    
    if (simplified->get_kind() == VN_EXPR::LITERAL && 
-#ifdef TARG_X8664
-       !MTYPE_is_vector(TCON_ty(simplified->get_tcon())) &&
-#endif
-       MTYPE_is_integral(TCON_ty(simplified->get_tcon())))
+       MTYPE_is_integral(TCON_ty(simplified->get_tcon())) &&
+       !(static_cast<const VN_LITERAL_EXPR*>(simplified))->is_const_vect ())
    {
       const BOOL  is_signed = MTYPE_is_signed(TCON_ty(simplified->get_tcon()));
       const INT64 intval = Targ_To_Host(simplified->get_tcon());
@@ -699,17 +697,26 @@
         break;
 
       case CK_CONST:
-        valnum = _valnum_integer(cr->Const_val(), 
-                                 MTYPE_is_signed(cr->Dtyp()));
-        _set_valnum(exprid, valnum, _exprid_to_vn, *_status.locked_to_vn);
-        break;
+         // Constant vector, no matter its element type is int or fp, is 
+         // depicted by a CR of type CK_RCONST. 
+         //
+         Is_True (!MTYPE_is_vector (cr->Dtyp()),
+                  ("vect cannot be described by a CR_CONST"));
+         valnum = _valnum_integer(cr->Const_val(), 
+                                  MTYPE_is_signed(cr->Dtyp()));
+         _set_valnum(exprid, valnum, _exprid_to_vn, *_status.locked_to_vn);
+         break;
 
       case CK_RCONST:
-        vn_expr_ptr = VN_EXPR::Create_Literal(STC_val(cr->Const_id()));
-        valnum = _valnum_vn_expr(exprid, vn_expr_ptr,
-                                 _exprid_to_vn,
-                                 *_status.locked_to_vn);
-        break;
+         {
+         TYPE_ID vect_ty = MTYPE_is_vector(cr->Dtyp()) ? 
+                             cr->Dtyp() : MTYPE_UNKNOWN;
+         vn_expr_ptr = VN_EXPR::Create_Literal(STC_val(cr->Const_id()), 
vect_ty);
+         valnum = _valnum_vn_expr(exprid, vn_expr_ptr,
+                                  _exprid_to_vn,
+                                  *_status.locked_to_vn);
+         }
+         break;
 
       case CK_IVAR:
         if (cr->Opr() == OPR_PARM)

Modified: trunk/osprey/be/opt/opt_vn_expr.cxx
===================================================================
--- trunk/osprey/be/opt/opt_vn_expr.cxx 2011-04-20 08:20:21 UTC (rev 3565)
+++ trunk/osprey/be/opt/opt_vn_expr.cxx 2011-04-21 23:43:17 UTC (rev 3566)
@@ -130,15 +130,23 @@
                      VN_EXPR::CONST_PTR opnd1, 
                      VN_EXPR::CONST_PTR opnd2)
 {
+   if ((static_cast<const VN_LITERAL_EXPR*>(opnd1))->is_const_vect () ||
+       (static_cast<const VN_LITERAL_EXPR*>(opnd2))->is_const_vect ()) {
+     FmtAssert (FALSE, ("not yet able to fold constant vector"));
+   }
+
    // Returns NULL if we cannot fold the given TCONs.
    //
    BOOL folded = FALSE;
    TCON tcon1 = opnd1->get_tcon();
    TCON tcon2 = opnd2->get_tcon();
    TCON tcon = Targ_WhirlOp(opc, tcon1, tcon2, &folded);
-   if (folded)
-      return VN_EXPR::Create_Literal(tcon); // Create new literal VN_EXPR;
-   else
+   if (folded) {
+     // Create new literal VN_EXPR;
+      TYPE_ID vect_ty = (static_cast<const VN_LITERAL_EXPR*>(opnd1))->
+                            get_vect_type ();
+      return VN_EXPR::Create_Literal(tcon, vect_ty);
+   } else
       return NULL;
 }
 
@@ -300,14 +308,14 @@
    case MTYPE_U2:
    case MTYPE_U4:
    case MTYPE_U8:
-      p = VN_EXPR::Create_Literal(Host_To_Targ(mty, i));
+      p = VN_EXPR::Create_Literal(Host_To_Targ(mty, i), MTYPE_UNKNOWN);
       break;
         
    case MTYPE_F4:
    case MTYPE_F8:
    case MTYPE_F10:
    case MTYPE_FQ:
-      p = VN_EXPR::Create_Literal(Host_To_Targ_Float(mty, i));
+      p = VN_EXPR::Create_Literal(Host_To_Targ_Float(mty, i), MTYPE_UNKNOWN);
       break;
       
    default:
@@ -383,9 +391,9 @@
 
 
 VN_EXPR::PTR 
-VN_EXPR::Create_Literal(const TCON &tcon)
+VN_EXPR::Create_Literal(const TCON &tcon, TYPE_ID vect_ty)
 {
-   return VN_LITERAL_EXPR::Create(tcon);
+   return VN_LITERAL_EXPR::Create(tcon, vect_ty);
 }
 
 
@@ -603,9 +611,14 @@
       const MTYPE other_mty = TCON_ty(other_tcon);
 
 #ifdef TARG_X8664
+      // FIXME: this is statement is a nop as TCON_ty() won't return vector ty.
       if (MTYPE_is_vector(this_mty) ||         MTYPE_is_vector(other_mty))
        return FALSE;
 #endif
+      
+      if (_vect_ty != (static_cast<const VN_LITERAL_EXPR*>(expr))->_vect_ty)
+        return FALSE;
+
       if (MTYPE_is_integral(this_mty) && MTYPE_is_integral(other_mty))
       {
         // We only care about the value and the signedness of integral types,
@@ -639,8 +652,7 @@
                  TCON_R4(other_tcon) == 0 && TCON_R4(_tcon) == 0)
            truth = TCON_word0(other_tcon) == TCON_word0(_tcon);
 #endif
-        else
-        {
+         else {
            BOOL folded;
            other_tcon = 
               Targ_WhirlOp(OPCODE_make_op(OPR_EQ, 
@@ -699,8 +711,14 @@
    }
    else if (Is_Literal_Expr(opnd))
    {
+     if (MTYPE_is_vector (OPCODE_rtype(_opc))) {
+       // TODO: handle expression like "OPC_V16F4V16I4CVT V16I4-const"
+       //
+     } else if ((static_cast<const VN_LITERAL_EXPR*>(opnd))->is_const_vect ()) 
{
+       // TODO: handle expression like "OPC_F4V16F4REDUCE_ADD VF6F4-const"  
+       //
+     } else if (
      // for IA-32, do not fold away I8I4CVT
-     if (
 #ifndef TARG_X8664
          !Split_64_Bit_Int_Ops ||
 #endif
@@ -1264,16 +1282,7 @@
    CONST_PTR      opnd2 = v->valnum_expr(_vn[1]);
    const BOOL     is_integral = 
       (OPERATOR_is_compare(opr)? 
-       MTYPE_is_integral(OPCODE_desc(_opc)) 
-#ifdef TARG_X8664 // bug 7554
-               && ! MTYPE_is_vector(OPCODE_desc(_opc))
-#endif
-       :
-       MTYPE_is_integral(rty)
-#ifdef TARG_X8664 // bug 7554
-               && ! MTYPE_is_vector(rty)
-#endif
-       );
+       MTYPE_is_integral(OPCODE_desc(_opc)) : MTYPE_is_integral(rty));
 
    PTR   simplified = this;
    INT64 intconst;
@@ -1288,6 +1297,8 @@
    if (has_bottom_opnd() || has_top_opnd())
    {
       simplified = Create_Unary(OPC_VPARM, VN_VALNUM::Bottom());
+   } else if (MTYPE_is_vector(rty)) {
+      // TODO : perform simplification for vectorized bin-op.
    }
    else if (Is_Literal_Expr(opnd1) && Is_Literal_Expr(opnd2))
    {
@@ -1512,7 +1523,7 @@
            if (intconst == 0)
               simplified = Create_Unary(OPC_VPARM, _vn[0]);
            else if (intconst != 0)
-              simplified = Create_Literal(opnd2->get_tcon());
+              simplified = Create_Literal(opnd2->get_tcon(), MTYPE_UNKNOWN);
         }
         else if (Is_Literal_Expr(opnd1))
         {
@@ -1520,7 +1531,7 @@
            if (intconst == 0)
               simplified = Create_Unary(OPC_VPARM, _vn[1]);
            else if (intconst != 0)
-              simplified = Create_Literal(opnd1->get_tcon());
+              simplified = Create_Literal(opnd1->get_tcon(), MTYPE_UNKNOWN);
         }
         break;
 
@@ -1692,7 +1703,7 @@
         TCON folded_tcon = Targ_IntrinsicOp(_intr_opc, arg_tconsts, &folded);
         if (folded)
         {
-           simplified = Create_Literal(folded_tcon);
+           simplified = Create_Literal(folded_tcon, MTYPE_UNKNOWN);
         }
       }
    }

Modified: trunk/osprey/be/opt/opt_vn_expr.h
===================================================================
--- trunk/osprey/be/opt/opt_vn_expr.h   2011-04-20 08:20:21 UTC (rev 3565)
+++ trunk/osprey/be/opt/opt_vn_expr.h   2011-04-21 23:43:17 UTC (rev 3566)
@@ -323,7 +323,7 @@
    //     opnd(1..num_dims())                       == dimension_size
    //     opnd(num_dims()+1..num_dims()+num_dims()) == index
    //
-   static PTR Create_Literal(const TCON &tcon);
+   static PTR Create_Literal(const TCON &elem_ton, TYPE_ID vect_ty);
    static PTR Create_Unary(OPCODE opc, 
                           const VN_VALNUM &vn1);
    static PTR Create_Binary(OPCODE opc, 

Modified: trunk/osprey/be/opt/opt_vn_expr_taxonomy.h
===================================================================
--- trunk/osprey/be/opt/opt_vn_expr_taxonomy.h  2011-04-20 08:20:21 UTC (rev 
3565)
+++ trunk/osprey/be/opt/opt_vn_expr_taxonomy.h  2011-04-21 23:43:17 UTC (rev 
3566)
@@ -214,25 +214,46 @@
    
    static FREE_STACK *_Free;
 
+   // If the liternal is a vector, the <_vect_ty> indicates the vector 
+   // type, and the _tcon hold the elements value. All elements should
+   // hold same value.
+   // 
+   // If the liternal is a scalar, _vect_ty should be set to MTYPE_UNKNOWN.
+   //
    TCON _tcon;
+   TYPE_ID _vect_ty;
 
-   VN_LITERAL_EXPR(const TCON &tcon) : _tcon(tcon) {}
-   
+   VN_LITERAL_EXPR(const TCON &tcon) : _tcon(tcon) {} 
 public:
 
    static void Init_Free_List() {_Free = CXX_NEW(FREE_STACK(_Mpool), _Mpool);}
    static void Reclaim_Free_List() {CXX_DELETE(_Free, _Mpool); _Free = NULL;}
   
-   static VN_LITERAL_EXPR *Create(const TCON &tcon) 
+   static VN_LITERAL_EXPR *Create(const TCON &tcon, TYPE_ID vect_ty) 
    {
       VN_LITERAL_EXPR *expr = (VN_LITERAL_EXPR *)_Free->pop();
       if (expr == NULL)
         expr = CXX_NEW(VN_LITERAL_EXPR(tcon), _Mpool);
       else
         expr->_tcon = tcon;
+
+      expr->_vect_ty = vect_ty;
+      Is_True (vect_ty == MTYPE_UNKNOWN || MTYPE_is_vector (vect_ty),
+               ("vect_ty is invalid"));
+
       return expr;
    }
 
+   BOOL is_const_vect (void) const {
+     if (_vect_ty != MTYPE_UNKNOWN) {
+       Is_True (MTYPE_is_vector (_vect_ty), ("isn't vector type"));
+       return TRUE;
+     }
+     return FALSE;
+   }
+
+   TYPE_ID get_vect_type (void) const { return _vect_ty; }
+
    void free() 
    {
       _Free->push(this);
@@ -278,9 +299,13 @@
    
    BOOL is_equal_to(CONST_PTR expr) const;
 
+   // Gee, why make dump function inlinable?
+   //
    void print(FILE *fp = stderr) const
    {
-      fprintf(fp, "%s_const", MTYPE_name(TCON_ty(_tcon)));
+      fprintf(fp, "%s_const", 
+              _vect_ty == MTYPE_UNKNOWN ? 
+              MTYPE_name(TCON_ty(_tcon)) : MTYPE_name(_vect_ty));
       fprintf(fp, "(%s)", Targ_Print(NULL, _tcon)); // Using default formatting
    }
 

Modified: trunk/osprey/be/opt/opt_vnfre.cxx
===================================================================
--- trunk/osprey/be/opt/opt_vnfre.cxx   2011-04-20 08:20:21 UTC (rev 3565)
+++ trunk/osprey/be/opt/opt_vnfre.cxx   2011-04-21 23:43:17 UTC (rev 3566)
@@ -109,6 +109,7 @@
 #include "opt_lftr2.h"  // Should we ever create any of these?
 #include "opt_vn.h"
 #include "opt_vn_ivc.h" // Induction variable classification for coalescing
+#include "opt_vn_expr_taxonomy.h"
 
 // #define DO_VNFRE_TRACE 1
 
@@ -3330,10 +3331,10 @@
    TCON            tcon = expr->get_tcon();
    EXP_OCCURS *    occ;
    EXP_OCCURS_ITER occ_iter;
+   TYPE_ID vect_ty = (static_cast<const 
VN_LITERAL_EXPR*>(expr))->get_vect_type ();
    FOR_ALL_NODE(occ, occ_iter, Init(head))
    {
-      _etable->Replace_by_const(occ, tcon);
-        
+      _etable->Replace_by_const(occ, tcon, vect_ty);
    }
 } // VALNUM_FRE::_substitute_literal
 


------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been 
demonstrated beyond question. Learn why your peers are replacing JEE 
containers with lightweight application servers - and what you can gain 
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to