Author: shihui
Date: 2010-11-16 20:07:18 -0500 (Tue, 16 Nov 2010)
New Revision: 3402

Modified:
   trunk/osprey/be/cg/cflow.cxx
Log:
Fix an O1 bug in cflow optimization exposed when a cmpi32 is changed to cmpi8

test case
int main()
{
long long ll = 0x7EF0LL;
unsigned char c = (char) ll;
if (c != 0xf0)
   return 1;
return 0;
}

[   3, 0] TN149 :- ldc64 (0x7ef0) ;
[   3, 0] :- store64 TN149 GTN4(%rsp) (sym:ll+0) ;
[   4, 0] :- store8 TN149 GTN4(%rsp) (sym:c+0) ;
[   5, 0] TN33(%rflags) :- cmpi8 TN149 (0xf0) ;
[   5, 0] :- je TN33(%rflags) (lab:.L_0_770) ;

convert_if_to_goto get TN149's value is 0x7ef0, then directly compare with 0xf0 
without truncate.
The fix is truncate the constant to one bytes or two bytes if compare is short 
unsigned compare.

Reviewed by Jianxin


Modified: trunk/osprey/be/cg/cflow.cxx
===================================================================
--- trunk/osprey/be/cg/cflow.cxx        2010-11-16 00:18:31 UTC (rev 3401)
+++ trunk/osprey/be/cg/cflow.cxx        2010-11-17 01:07:18 UTC (rev 3402)
@@ -331,9 +331,9 @@
 }
 
 static void
-Extend_Short_Cmp_Src(OP* compare_op, VARIANT br_variant, INT64 *v)
+Extend_Truncate_Short_Cmp_Src(OP* compare_op, VARIANT br_variant, INT64 *v)
 {
-  // only consider sign comparision
+  BOOL is_sign;
   switch (br_variant) {
     case V_BR_I4EQ:
     case V_BR_I4NE:
@@ -347,9 +347,24 @@
     case V_BR_I8GT: 
     case V_BR_I8LE: 
     case V_BR_I8LT:
-        break;
+      is_sign = TRUE;
+      break;
+    case V_BR_U4EQ:
+    case V_BR_U4NE:
+    case V_BR_U4GT:
+    case V_BR_U4GE:
+    case V_BR_U4LT:
+    case V_BR_U4LE:
+    case V_BR_U8EQ:
+    case V_BR_U8NE:
+    case V_BR_U8GT:
+    case V_BR_U8GE:
+    case V_BR_U8LT:
+    case V_BR_U8LE:
+      is_sign = FALSE;
+      break;
     default:
-        return;
+      return;
   }
 
   // sign extend the constant value
@@ -368,7 +383,10 @@
     case TOP_cmpxi8:
     case TOP_cmpxxi8:
     case TOP_cmpxxxi8:
-      *v = ( (*v) << ( sizeof(INT64) * 8 - 8 ) ) >> ( sizeof(INT64) * 8 - 8 );
+      if(is_sign)
+        *v = ( (*v) << ( sizeof(INT64) * 8 - 8 ) ) >> ( sizeof(INT64) * 8 - 8 
);
+      else
+        *v = *v & 0xff;
       return;
     case TOP_test16:
     case TOP_testx16:
@@ -383,8 +401,10 @@
     case TOP_cmpxi16:
     case TOP_cmpxxi16:
     case TOP_cmpxxxi16:
-      *v = ( (*v) << ( sizeof(INT64) * 8 - 16 ) ) >> ( sizeof(INT64) * 8 - 16 
);
-      return;
+      if(is_sign)
+        *v = ( (*v) << ( sizeof(INT64) * 8 - 16 ) ) >> ( sizeof(INT64) * 8 - 
16 );
+      else
+        *v = *v & 0xffff;
   }
 }
 #endif
@@ -2686,12 +2706,12 @@
 
   if (!TN_Value_At_Op(tn1, compare_op, &v1)) goto try_identities;
 #ifdef TARG_X8664
-  Extend_Short_Cmp_Src(compare_op, br_variant, &v1);
+  Extend_Truncate_Short_Cmp_Src(compare_op, br_variant, &v1);
 #endif
 
   if (tn2 && !TN_Value_At_Op(tn2, compare_op, &v2)) goto try_identities;
 #ifdef TARG_X8664
-  Extend_Short_Cmp_Src(compare_op, br_variant, &v2);
+  Extend_Truncate_Short_Cmp_Src(compare_op, br_variant, &v2);
 #endif
 
   /* Evaluate the condition.


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to