dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_oper.tc,1.29,1.30


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_oper.tc,1.29,1.30
Date: Wed, 20 Nov 2002 06:36:57 -0500

Update of /cvsroot/dotgnu-pnet/pnet/cscc/csharp
In directory subversions:/tmp/cvs-serv22390/cscc/csharp

Modified Files:
        cs_oper.tc 
Log Message:
start simple arithmetic optimizations


Index: cs_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_oper.tc,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** cs_oper.tc  18 Nov 2002 20:15:56 -0000      1.29
--- cs_oper.tc  20 Nov 2002 11:36:54 -0000      1.30
***************
*** 126,129 ****
--- 126,345 ----
  
  /*
+  * Bit count stuff to get the correct power of 2 for stuff
+  */
+ static int IsPowOfTwo(ILEvalValue evalValue)
+ {
+       int bitpos=-1;
+       int bitcount=0;
+       ILUInt32 word;
+       if(evalValue.un.i4Value < 0)
+       {
+               switch(evalValue.valueType)
+               {
+                       case ILMachineType_UInt8:
+                       case ILMachineType_UInt16:
+                       case ILMachineType_UInt32:
+                       case ILMachineType_UInt64:
+                               break;
+                       default:
+                               return -1;
+               }
+       }
+       for(word=evalValue.un.i4Value;word!=0;word=word>>1)
+       {
+               if(word & 0x01)bitcount++;
+               bitpos++;
+       }
+       if(bitcount==1)return bitpos;
+       return -1;
+ }
+ /*
+  * Reduce operator strength for operators
+  */
+ static void ReduceOperator(ILGenInfo *info, ILNode *node,
+                                            ILNode **parent, CSSemValue 
*result)
+ {
+       ILEvalValue evalValue;
+       ILNode_BinaryExpression *expr;
+       int bitpos;
+       if(info->overflowInsns || !(info->optimizeFlag))
+       {
+               return;
+       }
+       if(yyisa(node,ILNode_BinaryExpression))
+       {
+               expr=(ILNode_BinaryExpression*)(node);
+               switch(ILNode_GetType(expr->expr1,info))
+               {
+                       case ILMachineType_Int8:
+                       case ILMachineType_UInt8:
+                       case ILMachineType_Int16:
+                       case ILMachineType_UInt16:
+                       case ILMachineType_Int32:
+                       case ILMachineType_UInt32:
+                       case ILMachineType_Int64:
+                       case ILMachineType_UInt64:
+                               break;
+                       default:
+                               return; // expr1 not integer
+               }
+               switch(ILNode_GetType(expr->expr2,info))
+               {
+                       case ILMachineType_Int8:
+                       case ILMachineType_UInt8:
+                       case ILMachineType_Int16:
+                       case ILMachineType_UInt16:
+                       case ILMachineType_Int32:
+                       case ILMachineType_UInt32:
+                       case ILMachineType_Int64:
+                       case ILMachineType_UInt64:
+                               break;
+                       default:
+                               return; // expr2 not integer
+               }
+               /*
+               * NOTE:
+               * expr1 < expr2 
+               *       Multiply:        expr2 << value1, 0
+               *       Div: 0
+               */
+               if(ILNode_GetType(expr->expr1,info) < 
ILNode_GetType(expr->expr2,info))
+               {
+                       if(ILNode_EvalConst(expr->expr1,info,&evalValue))
+                       {
+                               if((bitpos=IsPowOfTwo(evalValue))!=-1)
+                               {
+                                       if(yyisa(node,ILNode_Mul))
+                                       {
+                                               
*parent=ILNode_Shl_create(expr->expr2,
+                                                       
ILNode_Int32_create(bitpos,0,0));
+                                       }
+                               }
+                               else if(evalValue.un.i4Value==0)
+                               {
+                                       if(yyisa(node,ILNode_Mul) || 
yyisa(node,ILNode_Div))
+                                       {
+                                               
*parent=ILNode_Int32_create(0,0,0);
+                                       }
+                               }
+                       }
+                       else if(ILNode_EvalConst(expr->expr2,info,&evalValue))
+                       {
+                               if((bitpos=IsPowOfTwo(evalValue))!=-1)
+                               {
+                               /* FIXME: uncomment after adding check_range */
+                               /*
+                                       if(yyisa(node,ILNode_Mul))
+                                       {
+                                               
*parent=ILNode_Shl_create(expr->expr1,
+                                                       
ILNode_Int32_create(bitpos,0,0));
+                                       }*/
+                               }
+                               else if(evalValue.un.i4Value==0)
+                               {
+                                       if(yyisa(node,ILNode_Mul))
+                                       {
+                                               
*parent=ILNode_Int32_create(0,0,0);
+                                       }
+                               }
+                       }
+               }
+               /*
+               * NOTE:
+               * expr1 > expr2 
+               *       Multiply:        expr1 << value2, 0
+               *       Div: expr1 >> value 2
+               */
+               else if(ILNode_GetType(expr->expr1,info) > 
+                                               
ILNode_GetType(expr->expr2,info))
+               {
+                       if(ILNode_EvalConst(expr->expr1,info,&evalValue))
+                       {
+                               if(evalValue.un.i4Value==0)
+                               {
+                                       if(yyisa(node,ILNode_Mul) || 
yyisa(node,ILNode_Div))
+                                       {
+                                               
*parent=ILNode_Int32_create(0,0,0);
+                                       }
+                               }
+                       }
+                       else if(ILNode_EvalConst(expr->expr2,info,&evalValue))
+                       {
+                               if((bitpos=IsPowOfTwo(evalValue))!=-1)
+                               {
+                                       if(yyisa(node,ILNode_Mul))
+                                       {
+                                               
*parent=ILNode_Shl_create(expr->expr1,
+                                                       
ILNode_Int32_create(bitpos,0,0));
+                                       }
+                                       if(yyisa(node,ILNode_Div))
+                                       {
+                                               
*parent=ILNode_Shr_create(expr->expr1,
+                                                       
ILNode_Int32_create(bitpos,0,0));
+                                       }
+                               }
+                               else if(evalValue.un.i4Value==0)
+                               {
+                                       if(yyisa(node,ILNode_Mul))
+                                       {
+                                               
*parent=ILNode_Int32_create(0,0,0);
+                                       }
+                               }
+                       }
+               }
+               /*
+               * NOTE:
+               * expr1 == expr2 
+               *       Multiply:        expr1 << value2, expr2 >> value1,  0
+               *       Div: expr1 >> value 2, expr2 << value1, 0
+               */
+               else
+               {
+                       if(ILNode_EvalConst(expr->expr1,info,&evalValue))
+                       {
+                               if((bitpos=IsPowOfTwo(evalValue))!=-1)
+                               {
+                                       if(yyisa(node,ILNode_Mul))
+                                       {
+                                               
*parent=ILNode_Shl_create(expr->expr2,
+                                                       
ILNode_Int32_create(bitpos,0,0));
+                                       }
+                               }
+                               else if(evalValue.un.i4Value==0)
+                               {
+                                       if(yyisa(node,ILNode_Mul) || 
yyisa(node,ILNode_Div))
+                                       {
+                                               
*parent=ILNode_Int32_create(0,0,0);
+                                       }
+                               }
+                       }
+                       else if(ILNode_EvalConst(expr->expr2,info,&evalValue))
+                       {
+                               if((bitpos=IsPowOfTwo(evalValue))!=-1)
+                               {
+                                       if(yyisa(node,ILNode_Mul))
+                                       {
+                                               
*parent=ILNode_Shl_create(expr->expr1,
+                                                       
ILNode_Int32_create(bitpos,0,0));
+                                       }
+                                       if(yyisa(node,ILNode_Div))
+                                       {
+                                               
*parent=ILNode_Shr_create(expr->expr1,
+                                                       
ILNode_Int32_create(bitpos,0,0));
+                                       }
+                               }
+                               else if(evalValue.un.i4Value==0)
+                               {
+                                       if(yyisa(node,ILNode_Mul) || 
yyisa(node,ILNode_Div))
+                                       {
+                                               
*parent=ILNode_Int32_create(0,0,0);
+                                       }
+                               }
+                       }
+               }
+       }
+ }
+ 
+ /*
   * Determine if a semantic value is zero.  Used to support
   * implicit coercions from zero to enumerated types.
***************
*** 206,209 ****
--- 422,426 ----
                }
                EvalOperator(info, *parent, parent, &value1);
+               ReduceOperator(info,*parent,parent, &value1);
                return value1;
        }
***************
*** 257,260 ****
--- 474,478 ----
                }
                EvalOperator(info, *parent, parent, &value1);
+               ReduceOperator(info,*parent,parent, &value1);
                return value1;
        }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]