View | Details | Return to bug 28632 | Differences between
and this patch

Collapse All | Expand All

(-)gcc-4.1.1/gcc/tree-vrp.c.orig (-4 / +128 lines)
Lines 1086-1092 extract_range_from_ssa_name (value_range Link Here
1086
   are not using wrapping arithmetic, then adjust the result to be
1086
   are not using wrapping arithmetic, then adjust the result to be
1087
   -INF or +INF depending on CODE, VAL1 and VAL2.  */
1087
   -INF or +INF depending on CODE, VAL1 and VAL2.  */
1088
1088
1089
static inline tree
1089
static tree
1090
vrp_int_const_binop (enum tree_code code, tree val1, tree val2)
1090
vrp_int_const_binop (enum tree_code code, tree val1, tree val2)
1091
{
1091
{
1092
  tree res;
1092
  tree res;
Lines 1182-1187 vrp_int_const_binop (enum tree_code code Link Here
1182
}
1182
}
1183
1183
1184
1184
1185
/* Example: let's say operand has:
1186
max = 01010010101001010010
1187
min = 01010010100000010010
1188
We can infer that these bits will be set
1189
in any possible value of the operand:
1190
      01010010100000000000
1191
*/
1192
static tree
1193
find_bits1 (tree min, tree max)
1194
{
1195
  tree xored, shift, always1;
1196
  int xor_hi;
1197
1198
  always1 = vrp_int_const_binop(BIT_AND_EXPR, min, max);
1199
  xored = vrp_int_const_binop(BIT_XOR_EXPR, min, max);
1200
  xor_hi = tree_floor_log2(xored);
1201
  if(xor_hi >= 0) /* if min!=max */
1202
    {
1203
      shift = build_int_cst (NULL_TREE, xor_hi+1);
1204
      always1 = vrp_int_const_binop(RSHIFT_EXPR, always1, shift);
1205
      always1 = vrp_int_const_binop(LSHIFT_EXPR, always1, shift);
1206
    }
1207
  return always1;
1208
}
1209
/* Example: let's say operand has:
1210
max = 01010010101001010010
1211
min = 01010010100000010010
1212
We can infer that these bits will be unset
1213
in any possible value of the operand:
1214
      01010010101111111111
1215
*/
1216
static tree
1217
find_bits0 (tree min, tree max)
1218
{
1219
  tree xored, always0, tmp;
1220
  int xor_hi;
1221
1222
  always0 = vrp_int_const_binop(BIT_IOR_EXPR, min, max);
1223
  xored = vrp_int_const_binop(BIT_XOR_EXPR, min, max);
1224
  xor_hi = tree_floor_log2(xored);
1225
  if(xor_hi > 0) /* if min!=max and difference is not in lowest bit only */
1226
    {
1227
      tmp = build_int_cst (NULL_TREE, xor_hi);
1228
      always0 = vrp_int_const_binop(RSHIFT_EXPR, always0, tmp);
1229
      /* Too ugly for words */
1230
      tmp = build_int_cst (NULL_TREE, 1);
1231
      do
1232
        {
1233
          always0 = vrp_int_const_binop(LSHIFT_EXPR, always0, tmp);
1234
          always0 = vrp_int_const_binop(PLUS_EXPR, always0, tmp);
1235
          xor_hi--;
1236
        }
1237
      while(xor_hi);
1238
    }
1239
  return always0;
1240
}
1241
1185
/* Extract range information from a binary expression EXPR based on
1242
/* Extract range information from a binary expression EXPR based on
1186
   the ranges of each of its operands and the expression code.  */
1243
   the ranges of each of its operands and the expression code.  */
1187
1244
Lines 1206-1211 extract_range_from_binary_expr (value_ra Link Here
1206
      && code != ROUND_DIV_EXPR
1263
      && code != ROUND_DIV_EXPR
1207
      && code != MIN_EXPR
1264
      && code != MIN_EXPR
1208
      && code != MAX_EXPR
1265
      && code != MAX_EXPR
1266
      && code != BIT_AND_EXPR
1267
      && code != BIT_IOR_EXPR
1209
      && code != TRUTH_ANDIF_EXPR
1268
      && code != TRUTH_ANDIF_EXPR
1210
      && code != TRUTH_ORIF_EXPR
1269
      && code != TRUTH_ORIF_EXPR
1211
      && code != TRUTH_AND_EXPR
1270
      && code != TRUTH_AND_EXPR
Lines 1234-1239 extract_range_from_binary_expr (value_ra Link Here
1234
  else
1293
  else
1235
    set_value_range_to_varying (&vr1);
1294
    set_value_range_to_varying (&vr1);
1236
1295
1296
  /* Bitwise ops */
1297
  if (code == BIT_AND_EXPR)
1298
    {
1299
      if (vr0.type == VR_RANGE || vr1.type == VR_RANGE)
1300
        {
1301
          if(vr0.type == VR_RANGE)
1302
            {
1303
              if(vr1.type == VR_RANGE)
1304
                {
1305
                  tree always1_0, always1_1;
1306
                  always1_0 = find_bits1(vr0.min, vr0.max);
1307
                  always1_1 = find_bits1(vr1.min, vr1.max);
1308
                  min = vrp_int_const_binop(BIT_AND_EXPR, always1_0, always1_1);
1309
                  max = vrp_int_const_binop(MIN_EXPR, vr0.max, vr1.max);
1310
                }
1311
              else
1312
                {
1313
                  min = build_int_cst(TREE_TYPE(vr0.min), 0);
1314
                  max = vr0.max;
1315
                }
1316
              set_value_range (vr, vr0.type, min, max, NULL);
1317
            }
1318
          else
1319
            {
1320
              min = build_int_cst(TREE_TYPE(vr1.min), 0);
1321
              max = vr1.max;
1322
              set_value_range (vr, vr1.type, min, max, NULL);
1323
            }
1324
          return;
1325
        }
1326
      set_value_range_to_varying (vr);
1327
      return;
1328
    }
1329
  if (code == BIT_IOR_EXPR)
1330
    {
1331
      if (vr0.type == VR_RANGE || vr1.type == VR_RANGE)
1332
        {
1333
          if(vr0.type == VR_RANGE)
1334
            {
1335
              if(vr1.type == VR_RANGE)
1336
                {
1337
                  tree always0_0, always0_1;
1338
                  always0_0 = find_bits0(vr0.min, vr0.max);
1339
                  always0_1 = find_bits0(vr1.min, vr1.max);
1340
                  min = vrp_int_const_binop(MAX_EXPR, vr0.min, vr1.min);
1341
                  max = vrp_int_const_binop(BIT_IOR_EXPR, always0_0, always0_1);
1342
                }
1343
              else
1344
                {
1345
                  min = vr0.min;
1346
                  max = TYPE_MAX_VALUE(TREE_TYPE(vr0.max));
1347
                }
1348
              set_value_range (vr, vr0.type, min, max, NULL);
1349
            }
1350
          else
1351
            {
1352
              min = vr1.min;
1353
              max = TYPE_MAX_VALUE(TREE_TYPE(vr1.max));
1354
              set_value_range (vr, vr1.type, min, max, NULL);
1355
            }
1356
          return;
1357
        }
1358
      set_value_range_to_varying (vr);
1359
      return;
1360
    }
1361
1237
  /* If either range is UNDEFINED, so is the result.  */
1362
  /* If either range is UNDEFINED, so is the result.  */
1238
  if (vr0.type == VR_UNDEFINED || vr1.type == VR_UNDEFINED)
1363
  if (vr0.type == VR_UNDEFINED || vr1.type == VR_UNDEFINED)
1239
    {
1364
    {
Lines 1244-1252 extract_range_from_binary_expr (value_ra Link Here
1244
  /* Refuse to operate on VARYING ranges, ranges of different kinds
1369
  /* Refuse to operate on VARYING ranges, ranges of different kinds
1245
     and symbolic ranges.  TODO, we may be able to derive anti-ranges
1370
     and symbolic ranges.  TODO, we may be able to derive anti-ranges
1246
     in some cases.  */
1371
     in some cases.  */
1247
  if (vr0.type == VR_VARYING
1372
  if (vr0.type != vr1.type
1248
      || vr1.type == VR_VARYING
1373
      || vr0.type == VR_VARYING
1249
      || vr0.type != vr1.type
1250
      || symbolic_range_p (&vr0)
1374
      || symbolic_range_p (&vr0)
1251
      || symbolic_range_p (&vr1))
1375
      || symbolic_range_p (&vr1))
1252
    {
1376
    {

Return to bug 28632