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

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

[Dotgnu-pnet-commits] CVS: pnet/codegen cg_arith.tc,1.15,1.16


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/codegen cg_arith.tc,1.15,1.16
Date: Mon, 02 Dec 2002 05:16:20 -0500

Update of /cvsroot/dotgnu-pnet/pnet/codegen
In directory subversions:/tmp/cvs-serv4285/codegen

Modified Files:
        cg_arith.tc 
Log Message:
fix the optimization bug


Index: cg_arith.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_arith.tc,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** cg_arith.tc 27 Nov 2002 18:45:04 -0000      1.15
--- cg_arith.tc 2 Dec 2002 10:16:18 -0000       1.16
***************
*** 32,52 ****
        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; /* negative nums cannot do this */
                }
!       }
!       for(word=evalValue.un.i4Value;word!=0;word=word>>1)
!       {
!               if(word & 0x01)bitcount++;
!               bitpos++;
        }
        if(bitcount==1)return bitpos;
--- 32,80 ----
        int bitcount=0;
        ILUInt32 word;
!       ILUInt64 longWord;
!       switch(evalValue.valueType)
        {
!               case ILMachineType_Int8:
!               case ILMachineType_Int16:
!               case ILMachineType_Int32:
                {
!                       if(evalValue.un.i4Value<0)
!                       {
!                               return -1;
!                       }
                }
!               /* fall through */
!               case ILMachineType_UInt8:
!               case ILMachineType_UInt16:
!               case ILMachineType_UInt32:
!               {
!                       for(word=evalValue.un.i4Value;word!=0;word=word>>1)
!                       {
!                               if(word & 0x01)bitcount++;
!                               bitpos++;
!                       }
!               }
!               break;
!               
!               case ILMachineType_Int64:
!               {
!                       if(evalValue.un.i8Value<0)
!                       {
!                               return -1;
!                       }
!               }
!               /* fall through */
!               
!               case ILMachineType_UInt64:
!               {
!                       
for(longWord=evalValue.un.i8Value;longWord!=0;longWord=longWord>>1)
!                       {
!                               if(longWord & 0x01)bitcount++;
!                               bitpos++;
!                       }
!               }
!               break;
!               default:
!                       return -1;
        }
        if(bitcount==1)return bitpos;
***************
*** 71,74 ****
--- 99,110 ----
                return 0;
        }
+ 
+       expr=(ILNode_BinaryExpression*)(node);
+       if(!ILNode_EvalConst(expr->expr1,info,&evalValue) && 
+               !ILNode_EvalConst(expr->expr2,info,&evalValue))
+       {
+               return 0;
+       }
+       
        switch(commonType)
        {
***************
*** 81,168 ****
                case ILMachineType_Int64:
                case ILMachineType_UInt64:
-                       break;
-               default:
-                       return 0; // not integer
-       }
-       
-       expr=(ILNode_BinaryExpression*)(node);
-       
-       if(ILNode_EvalConst(expr->expr1,info,&evalValue))
-       {
-               if((bitpos=IsPowOfTwo(evalValue))>0)
-               {
-                       if(yyisa(node,ILNode_Mul))
-                       {
-                               *parent=ILNode_Shl_create(expr->expr2,
-                                                       
ILNode_Int32_create(bitpos,0,0));
-                               return 1;
-                       }
-               }
-               else if(evalValue.un.i4Value==1)
-               {
-                       if(yyisa(node,ILNode_Mul))
-                       {
-                               *parent=expr->expr2; // 1 * x = x;
-                               return 1;
-                       }
-               }       
-               else if(evalValue.un.i4Value==0)
-               {
-                       if(yyisa(node,ILNode_Mul) || yyisa(node,ILNode_Div))
-                       {
-                               *parent=ILNode_Int32_create(0,0,0); // 0 * x 
=0; 0/x = 0;
-                               return 1;
-                       }
-                       else if(yyisa(node,ILNode_Add))
-                       {
-                               *parent=expr->expr2; // 0 + x = x
-                               return 1;
-                       }
-                       else if(yyisa(node,ILNode_Sub))
-                       {
-                               *parent=ILNode_Neg_create(expr->expr2); // 0 - 
x = -x
-                               return 1;
-                       }
-               }
-       }
-       else if(ILNode_EvalConst(expr->expr2,info,&evalValue))
-       {
-               if((bitpos=IsPowOfTwo(evalValue))>0)
                {
!                       if(yyisa(node,ILNode_Mul))
!                       {
!                               *parent=ILNode_Shl_create(expr->expr1,
!                                                       
ILNode_Int32_create(bitpos,0,0));
!                               return 1;
!                       }
!                       else if(yyisa(node,ILNode_Div))
                        {
!                               *parent=ILNode_Shr_create(expr->expr1,
!                                                       
ILNode_Int32_create(bitpos,0,0));
!                               return 1;
!                       }
!               }
!               else if(evalValue.un.i4Value==1)
!               {
!                       if(yyisa(node,ILNode_Mul) || yyisa(node,ILNode_Div))
!                       {
!                               *parent=expr->expr1; //  x * 1 = x; x/1 = x;
!                               return 1;
!                       }
!               }       
!               else if(evalValue.un.i4Value==0)
!               {
!                       if(yyisa(node,ILNode_Mul))
!                       {
!                               *parent=ILNode_Int32_create(0,0,0); // x * 0 =0;
!                               return 1;
!                       }
!                       else if(yyisa(node,ILNode_Add) ||       
yyisa(node,ILNode_Sub))
!                       {
!                               *parent=expr->expr1; // x + 0 = x ; x-0=x;
!                               return 1;
                        }
                }
        }
        return 0;
  }
--- 117,156 ----
                case ILMachineType_Int64:
                case ILMachineType_UInt64:
                {
!                       if(ILNode_EvalConst(expr->expr1,info,&evalValue))
                        {
!                               if((bitpos=IsPowOfTwo(evalValue))>0)
!                               {
!                                       if(yyisa(node,ILNode_Mul))
!                                       {
!                                               
*parent=ILNode_Shl_create(expr->expr2,
!                                                                       
ILNode_Int32_create(bitpos,0,0));
!                                               return 1;
!                                       }
!                               }
!                       }
!                       else if(ILNode_EvalConst(expr->expr2,info,&evalValue))
!                       {
!                               if((bitpos=IsPowOfTwo(evalValue))>0)
!                               {
!                                       if(yyisa(node,ILNode_Mul))
!                                       {
!                                               
*parent=ILNode_Shl_create(expr->expr1,
!                                                                       
ILNode_Int32_create(bitpos,0,0));
!                                               return 1;
!                                       }
!                               }
!                               else if(yyisa(node,ILNode_Div))
!                               {
!                                       *parent=ILNode_Shr_create(expr->expr1,
!                                                               
ILNode_Int32_create(bitpos,0,0));
!                                       return 1;
!                               }
                        }
                }
+               default:
+                       break;
        }
+ 
        return 0;
  }





reply via email to

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