From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 67B66384F498 for ; Thu, 27 Jul 2023 12:00:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67B66384F498 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 67E331F383; Thu, 27 Jul 2023 12:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690459257; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=NMhpJVbvCeZHF2n2tasDVry/JyBfGwSPjbB0aDQwpts=; b=2AzgIZwyIDQtidqz7Kr3puxourKnBC87JEnfqixhlXlTosqhB3sb0sfGqe1RGA2iMAtS7d bzBu+h9PJR1zinmMdSBWaLLwVq3WQzyToHCmmGv/mQD3T1JeivgF+Jfpe23qNzdCYt6ZkM u4opsydozc1thYZzBYIHsE+FDhJdOTQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690459257; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=NMhpJVbvCeZHF2n2tasDVry/JyBfGwSPjbB0aDQwpts=; b=2MSeR/nm/R+x+qhhA+ZbI3m23meRcIL7mlMt7Cwps91kXwG4WHfWrPg/YG8HZ1s4nd3Zeu QuhOT31ETM5qTiBw== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 5AE842C142; Thu, 27 Jul 2023 12:00:57 +0000 (UTC) Date: Thu, 27 Jul 2023 12:00:56 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] tree-optimization/91838 - fix FAIL of g++.dg/opt/pr91838.C User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,MISSING_MID,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20230727120056.vfX48x5CnKviQiEDVDJJRVUo9XyYlMFzIDjvLrTYgkU@z> The following fixes the lack of simplification of a vector shift by an out-of-bounds shift value. For scalars this is done both by CCP and VRP but vectors are not handled there. This results in PR91838 differences in outcome dependent on whether a vector shift ISA is available and thus vector lowering does or does not expose scalar shifts here. The following adds a match.pd pattern to catch uniform out-of-bound shifts, simplifying them to zero when not sanitizing shift amounts. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK? Thanks, Richard. PR tree-optimization/91838 * match.pd (([rl]shift @0 out-of-bounds) -> zero): New pattern. --- gcc/match.pd | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index a443dc48634..eace7d635e7 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1059,6 +1059,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && tree_nop_conversion_p (type, TREE_TYPE (@1))) (lshift @0 @2))) +/* Shifts by precision or greater result in zero. */ +(for shift (lshift rshift) + (simplify + (shift @0 uniform_integer_cst_p@1) + (if (!(flag_sanitize & SANITIZE_SHIFT_EXPONENT) + /* Use a signed compare to leave negative shift counts alone. */ + && wi::ges_p (wi::to_wide (uniform_integer_cst_p (@1)), + element_precision (type))) + { build_zero_cst (type); }))) + /* Shifts by constants distribute over several binary operations, hence (X << C) + (Y << C) can be simplified to (X + Y) << C. */ (for op (plus minus) -- 2.35.3