tree-ssa-reassoc.c (optimize_range_tests_diff): Perform MINUS_EXPR in unsigned type...
authorJakub Jelinek <jakub@redhat.com>
Wed, 15 Oct 2014 10:33:02 +0000 (12:33 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 15 Oct 2014 10:33:02 +0000 (12:33 +0200)
* tree-ssa-reassoc.c (optimize_range_tests_diff): Perform
MINUS_EXPR in unsigned type to avoid undefined behavior.

From-SVN: r216252

gcc/ChangeLog
gcc/tree-ssa-reassoc.c

index 5bc3571e39f89f57f1ba4b24c951ca5fd072968b..211b1daf8c810a42bc18114e69705bf1e55f37c8 100644 (file)
@@ -1,3 +1,8 @@
+2014-10-15  Jakub Jelinek  <jakub@redhat.com>
+
+       * tree-ssa-reassoc.c (optimize_range_tests_diff): Perform
+       MINUS_EXPR in unsigned type to avoid undefined behavior.
+
 2014-10-15  Eric Botcazou  <ebotcazou@adacore.com>
 
        * stor-layout.c (self_referential_size): Do not promote arguments.
index 2e8337c8e6f65469dd24f2e886d77030abbb6209..4714a389eb35752d1892d25d337772bf7000b5bc 100644 (file)
@@ -2250,8 +2250,13 @@ optimize_range_tests_diff (enum tree_code opcode, tree type,
   if (tree_log2 (tem1) < 0)
     return false;
 
+  type = unsigned_type_for (type);
+  tem1 = fold_convert (type, tem1);
+  tem2 = fold_convert (type, tem2);
+  lowi = fold_convert (type, lowi);
   mask = fold_build1 (BIT_NOT_EXPR, type, tem1);
-  tem1 = fold_binary (MINUS_EXPR, type, rangei->exp, lowi);
+  tem1 = fold_binary (MINUS_EXPR, type,
+                     fold_convert (type, rangei->exp), lowi);
   tem1 = fold_build2 (BIT_AND_EXPR, type, tem1, mask);
   lowj = build_int_cst (type, 0);
   if (update_range_test (rangei, rangej, 1, opcode, ops, tem1,