From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 941733858D33; Tue, 17 Oct 2023 22:44:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 941733858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697582663; bh=3dwlB6yHCLcB/StohQw6aC/gA6kmX2abGLTAHmXa6wE=; h=From:To:Subject:Date:From; b=Szw2izlquEW2lAe2hnfRJ/pJtrMAKIzEEulg30Ykm6g2X8HGklcPm1WqDjEj8ui4d ya6gv/6vbzX3exfd8sZKUQ4GCtarQ8VZcaPLv2+ySPl1RyPq/oPtJxbA2cx7LarCvO jBvpbY32lMrhWADr2h9kpjUapj2mtBAQeJaD34DQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4695] ssa_name_has_boolean_range vs signed-boolean:31 types X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 1fbb7d75abbb050f790d8b43422602ee4b152608 X-Git-Newrev: 5e4abf4233cd34212680cca700d6438445e6a16a Message-Id: <20231017224423.941733858D33@sourceware.org> Date: Tue, 17 Oct 2023 22:44:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5e4abf4233cd34212680cca700d6438445e6a16a commit r14-4695-g5e4abf4233cd34212680cca700d6438445e6a16a Author: Andrew Pinski Date: Fri Sep 1 22:09:08 2023 +0000 ssa_name_has_boolean_range vs signed-boolean:31 types This turns out to be a latent bug in ssa_name_has_boolean_range where it would return true for all boolean types but all of the uses of ssa_name_has_boolean_range was expecting 0/1 as the range rather than [-1,0]. So when I fixed vector lower to do all comparisons in boolean_type rather than still in the signed-boolean:31 type (to fix a different issue), the pattern in match for `-(type)!A -> (type)A - 1.` would assume A (which was signed-boolean:31) had a range of [0,1] which broke down and sometimes gave us -1/-2 as values rather than what we were expecting of -1/0. This was the simpliest patch I found while testing. We have another way of matching [0,1] range which we could use instead of ssa_name_has_boolean_range except that uses only the global ranges rather than the local range (during VRP). I tried to clean this up slightly by using gimple_match_zero_one_valuedp inside ssa_name_has_boolean_range but that failed because due to using only the global ranges. I then tried to change get_nonzero_bits to use the local ranges at the optimization time but that failed also because we would remove branches to __builtin_unreachable during evrp and lose information as we don't set the global ranges during evrp. OK? Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/110817 gcc/ChangeLog: * tree-ssanames.cc (ssa_name_has_boolean_range): Remove the check for boolean type as they don't have "[0,1]" range. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr110817-1.c: New test. * gcc.c-torture/execute/pr110817-2.c: New test. * gcc.c-torture/execute/pr110817-3.c: New test. Diff: --- gcc/testsuite/gcc.c-torture/execute/pr110817-1.c | 13 +++++++++++++ gcc/testsuite/gcc.c-torture/execute/pr110817-2.c | 16 ++++++++++++++++ gcc/testsuite/gcc.c-torture/execute/pr110817-3.c | 14 ++++++++++++++ gcc/tree-ssanames.cc | 4 ---- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110817-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110817-1.c new file mode 100644 index 000000000000..1d33fa9a207b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110817-1.c @@ -0,0 +1,13 @@ +typedef unsigned long __attribute__((__vector_size__ (8))) V; + + +V c; + +int +main (void) +{ + V v = ~((V) { } <=0); + if (v[0]) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110817-2.c b/gcc/testsuite/gcc.c-torture/execute/pr110817-2.c new file mode 100644 index 000000000000..1f759178425b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110817-2.c @@ -0,0 +1,16 @@ + +typedef unsigned char u8; +typedef unsigned __attribute__((__vector_size__ (8))) V; + +V v; +unsigned char c; + +int +main (void) +{ + V x = (v > 0) > (v != c); + // V x = foo (); + if (x[0] || x[1]) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110817-3.c b/gcc/testsuite/gcc.c-torture/execute/pr110817-3.c new file mode 100644 index 000000000000..36f09c88dd99 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110817-3.c @@ -0,0 +1,14 @@ +typedef unsigned __attribute__((__vector_size__ (1*sizeof(unsigned)))) V; + +V v; +unsigned char c; + +int +main (void) +{ + V x = (v > 0) > (v != c); + volatile signed int t = x[0]; + if (t) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc index 0a32444fbdf9..e26ef55b2bf5 100644 --- a/gcc/tree-ssanames.cc +++ b/gcc/tree-ssanames.cc @@ -522,10 +522,6 @@ ssa_name_has_boolean_range (tree op) { gcc_assert (TREE_CODE (op) == SSA_NAME); - /* Boolean types always have a range [0..1]. */ - if (TREE_CODE (TREE_TYPE (op)) == BOOLEAN_TYPE) - return true; - /* An integral type with a single bit of precision. */ if (INTEGRAL_TYPE_P (TREE_TYPE (op)) && TYPE_UNSIGNED (TREE_TYPE (op))