diff mbox series

[COMMITTED] Add relation processing to ubsan builtins, and EVRP equality.

Message ID fa3c0dd6-0008-d8a6-e009-ec41fe8a399c@redhat.com
State New
Headers show
Series [COMMITTED] Add relation processing to ubsan builtins, and EVRP equality. | expand

Commit Message

Andrew MacLeod July 12, 2021, 11:42 p.m. UTC
Ubsan builtins use the plus,minus and multiply operations under the 
covers, but they are not relation aware.  This patch queries for a 
relation between the 2 operands and passes that on to range-ops.

This resolves gcc.dg/pr97505.c when operating in ranger-only mode, and 
with that, ranger-only mode runs the gcc testsuite clean on 
x86_64-pc-linux-gnu.


If there are no objections, I'd like to change the default mode to 
ranger only, and see if something shows up on any other architectures, 
or in any other places.  We can easily switch back if need be.

I'll keep running things in hybrid mode locally to ensure we don't start 
losing parity with legacy EVRP.  Does this seem reasonable?

Andrew
diff mbox series

Patch

commit 9693ecdf7ed5dde9618d06560697ff8ee5e1e6b7
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Jul 12 14:38:42 2021 -0400

    Add relation processing to ubsan builtins.
    
    Ubsan builtins call the plus/minus/multiple fold routines, but did not
    use any relation information between the 2 operands that is available.
    query and pass any relations.
    This resolves gcc.dg/pr97505.c when operating in ranger-only mode.
    
            * gimple-range-fold.cc (fold_using_range::range_of_builtin_ubsan_call):
            Query relation between the 2 operands and use it.

diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 1fa4ace32b9..eff5d1f89f2 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -825,12 +825,14 @@  fold_using_range::range_of_builtin_ubsan_call (irange &r, gcall *call,
   tree arg1 = gimple_call_arg (call, 1);
   src.get_operand (ir0, arg0);
   src.get_operand (ir1, arg1);
+  // Check for any relation between arg0 and arg1.
+  relation_kind relation = src.query_relation (arg0, arg1);
 
   bool saved_flag_wrapv = flag_wrapv;
   // Pretend the arithmetic is wrapping.  If there is any overflow,
   // we'll complain, but will actually do wrapping operation.
   flag_wrapv = 1;
-  op->fold_range (r, type, ir0, ir1);
+  op->fold_range (r, type, ir0, ir1, relation);
   flag_wrapv = saved_flag_wrapv;
 
   // If for both arguments vrp_valueize returned non-NULL, this should