* [PATCH GCC]Make pointer overflow always undefined and remove the macro
@ 2017-07-24 8:43 Bin Cheng
2017-07-25 7:26 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Bin Cheng @ 2017-07-24 8:43 UTC (permalink / raw)
To: gcc-patches; +Cc: nd
[-- Attachment #1: Type: text/plain, Size: 876 bytes --]
Hi,
This is a followup patch to PR81388's fix. According to Richi,
POINTER_TYPE_OVERFLOW_UNDEFINED was added in -fstrict-overflow
warning work. Given:
A) strict-overflow was removed;
B) memory object can not wrap in address space;
C) existing code doesn't take it in consideration, as in nowrap_type_p.
This patch makes it always true thus removes definition/usage of the macro.
Bootstrap and test on x86_64 and AArch64. Is it OK?
Thanks,
bin
2017-07-20 Bin Cheng <bin.cheng@arm.com>
* tree.h (POINTER_TYPE_OVERFLOW_UNDEFINED): Delete.
* fold-const.c (fold_comparison, fold_binary_loc): Delete use of
above macro.
* match.pd: Ditto in address comparison pattern.
gcc/testsuite/ChangeLog
2017-07-20 Bin Cheng <bin.cheng@arm.com>
* gcc.dg/no-strict-overflow-7.c: Revise comment and test string.
* gcc.dg/tree-ssa/pr81388-1.c: Ditto.
[-- Attachment #2: undefined-overflow-pointer-20170721.txt --]
[-- Type: text/plain, Size: 5118 bytes --]
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 1bcbbb5..78bb326 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8505,14 +8505,9 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
{
/* We can fold this expression to a constant if the non-constant
offset parts are equal. */
- if ((offset0 == offset1
- || (offset0 && offset1
- && operand_equal_p (offset0, offset1, 0)))
- && (equality_code
- || (indirect_base0
- && (DECL_P (base0) || CONSTANT_CLASS_P (base0)))
- || POINTER_TYPE_OVERFLOW_UNDEFINED))
-
+ if (offset0 == offset1
+ || (offset0 && offset1
+ && operand_equal_p (offset0, offset1, 0)))
{
if (!equality_code
&& bitpos0 != bitpos1
@@ -8547,11 +8542,7 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
because pointer arithmetic is restricted to retain within an
object and overflow on pointer differences is undefined as of
6.5.6/8 and /9 with respect to the signed ptrdiff_t. */
- else if (bitpos0 == bitpos1
- && (equality_code
- || (indirect_base0
- && (DECL_P (base0) || CONSTANT_CLASS_P (base0)))
- || POINTER_TYPE_OVERFLOW_UNDEFINED))
+ else if (bitpos0 == bitpos1)
{
/* By converting to signed sizetype we cover middle-end pointer
arithmetic which operates on unsigned pointer types of size
@@ -9651,7 +9642,7 @@ fold_binary_loc (location_t loc,
/* With undefined overflow prefer doing association in a type
which wraps on overflow, if that is one of the operand types. */
- if ((POINTER_TYPE_P (type) && POINTER_TYPE_OVERFLOW_UNDEFINED)
+ if (POINTER_TYPE_P (type)
|| (INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_WRAPS (type)))
{
if (INTEGRAL_TYPE_P (TREE_TYPE (arg0))
@@ -9665,7 +9656,7 @@ fold_binary_loc (location_t loc,
/* With undefined overflow we can only associate constants with one
variable, and constants whose association doesn't overflow. */
- if ((POINTER_TYPE_P (atype) && POINTER_TYPE_OVERFLOW_UNDEFINED)
+ if (POINTER_TYPE_P (atype)
|| (INTEGRAL_TYPE_P (atype) && !TYPE_OVERFLOW_WRAPS (atype)))
{
if (var0 && var1)
diff --git a/gcc/match.pd b/gcc/match.pd
index 979085a..b89aed3 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3129,14 +3129,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
|| TREE_CODE (base1) == STRING_CST))
equal = (base0 == base1);
}
- (if (equal == 1
- && (cmp == EQ_EXPR || cmp == NE_EXPR
- /* If the offsets are equal we can ignore overflow. */
- || off0 == off1
- || POINTER_TYPE_OVERFLOW_UNDEFINED
- /* Or if we compare using pointers to decls or strings. */
- || (POINTER_TYPE_P (TREE_TYPE (@2))
- && (DECL_P (base0) || TREE_CODE (base0) == STRING_CST))))
+ (if (equal == 1)
(switch
(if (cmp == EQ_EXPR)
{ constant_boolean_node (off0 == off1, type); })
diff --git a/gcc/testsuite/gcc.dg/no-strict-overflow-7.c b/gcc/testsuite/gcc.dg/no-strict-overflow-7.c
index 19e1b55..0e73d48 100644
--- a/gcc/testsuite/gcc.dg/no-strict-overflow-7.c
+++ b/gcc/testsuite/gcc.dg/no-strict-overflow-7.c
@@ -3,8 +3,8 @@
/* Source: Ian Lance Taylor. Dual of strict-overflow-6.c. */
-/* We can only simplify the conditional when using strict overflow
- semantics. */
+/* We can simplify the conditional because pointer overflow always has
+ undefined semantics. */
int
foo (char* p)
@@ -12,4 +12,4 @@ foo (char* p)
return p + 1000 < p;
}
-/* { dg-final { scan-tree-dump "\[+\]\[ \]*1000" "optimized" } } */
+/* { dg-final { scan-tree-dump "return 0" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c
index ecfe129..0beb510 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fno-strict-overflow -fdump-tree-ivcanon-details" } */
+/* { dg-options "-O2 -fno-strict-overflow -fdump-tree-tailc-details" } */
void bar();
void foo(char *dst)
@@ -11,4 +11,6 @@ void foo(char *dst)
} while (dst < end);
}
-/* { dg-final { scan-tree-dump-times " zero if " 1 "ivcanon" } } */
+/* The loop only iterates once because pointer overflow always has undefined
+ semantics. As a result, call to bar becomes tail call. */
+/* { dg-final { scan-tree-dump-times "Found tail call " 1 "tailc" } } */
diff --git a/gcc/tree.h b/gcc/tree.h
index 91cf253..4e4edf2 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -859,9 +859,6 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
&& !TYPE_OVERFLOW_WRAPS (TYPE) \
&& (flag_sanitize & SANITIZE_SI_OVERFLOW))
-/* True if pointer types have undefined overflow. */
-#define POINTER_TYPE_OVERFLOW_UNDEFINED (!flag_wrapv)
-
/* Nonzero in a VAR_DECL or STRING_CST means assembler code has been written.
Nonzero in a FUNCTION_DECL means that the function has been compiled.
This is interesting in an inline function, since it might not need
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH GCC]Make pointer overflow always undefined and remove the macro
2017-07-24 8:43 [PATCH GCC]Make pointer overflow always undefined and remove the macro Bin Cheng
@ 2017-07-25 7:26 ` Richard Biener
2017-08-01 9:30 ` Bin.Cheng
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2017-07-25 7:26 UTC (permalink / raw)
To: Bin Cheng; +Cc: gcc-patches, nd
On Mon, Jul 24, 2017 at 10:43 AM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> This is a followup patch to PR81388's fix. According to Richi,
> POINTER_TYPE_OVERFLOW_UNDEFINED was added in -fstrict-overflow
> warning work. Given:
> A) strict-overflow was removed;
> B) memory object can not wrap in address space;
> C) existing code doesn't take it in consideration, as in nowrap_type_p.
> This patch makes it always true thus removes definition/usage of the macro.
> Bootstrap and test on x86_64 and AArch64. Is it OK?
Ok.
Please give others 24h to comment.
Thanks,
Richard.
> Thanks,
> bin
> 2017-07-20 Bin Cheng <bin.cheng@arm.com>
>
> * tree.h (POINTER_TYPE_OVERFLOW_UNDEFINED): Delete.
> * fold-const.c (fold_comparison, fold_binary_loc): Delete use of
> above macro.
> * match.pd: Ditto in address comparison pattern.
>
> gcc/testsuite/ChangeLog
> 2017-07-20 Bin Cheng <bin.cheng@arm.com>
>
> * gcc.dg/no-strict-overflow-7.c: Revise comment and test string.
> * gcc.dg/tree-ssa/pr81388-1.c: Ditto.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH GCC]Make pointer overflow always undefined and remove the macro
2017-07-25 7:26 ` Richard Biener
@ 2017-08-01 9:30 ` Bin.Cheng
0 siblings, 0 replies; 3+ messages in thread
From: Bin.Cheng @ 2017-08-01 9:30 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
On Tue, Jul 25, 2017 at 8:26 AM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Mon, Jul 24, 2017 at 10:43 AM, Bin Cheng <Bin.Cheng@arm.com> wrote:
>> Hi,
>> This is a followup patch to PR81388's fix. According to Richi,
>> POINTER_TYPE_OVERFLOW_UNDEFINED was added in -fstrict-overflow
>> warning work. Given:
>> A) strict-overflow was removed;
>> B) memory object can not wrap in address space;
>> C) existing code doesn't take it in consideration, as in nowrap_type_p.
>> This patch makes it always true thus removes definition/usage of the macro.
>> Bootstrap and test on x86_64 and AArch64. Is it OK?
>
> Ok.
>
> Please give others 24h to comment.
Hi,
I committed the patch as:
r250765 | amker | 2017-08-01 10:28:18 +0100 (Tue, 01 Aug 2017) | 9 lines
* tree.h (POINTER_TYPE_OVERFLOW_UNDEFINED): Delete.
* fold-const.c (fold_comparison, fold_binary_loc): Delete use of
above macro.
* match.pd: Ditto in address comparison pattern.
gcc/testsuite
* gcc.dg/no-strict-overflow-7.c: Revise comment and test string.
* gcc.dg/tree-ssa/pr81388-1.c: Ditto.
We can always revert it if there is any different opinions.
Thanks,
bin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-08-01 9:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-24 8:43 [PATCH GCC]Make pointer overflow always undefined and remove the macro Bin Cheng
2017-07-25 7:26 ` Richard Biener
2017-08-01 9:30 ` Bin.Cheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).