From patchwork Tue May 21 14:22:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1102824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-501340-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Dqm3Si1z"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 457dK16Z2pz9s1c for ; Wed, 22 May 2019 00:23:00 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=id2+mm00cCs+25a2vGhDllb8qBFvSBsPA97POMw9exwD+pLbBsEdK yI4BKJ/I5iaDnou6yCyXPjJddA1rciLqmwt7p0eCwRFBaAAbX6J3jIe5FMk2GVMC weWLqkxdMXv4Ze2oEB8kN/UV3F5/bZtzfDc1KDCa56essbOJb3MIIk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=T0mhks8jZqZVsR0mTPvxilNGcqs=; b=Dqm3Si1zu7brbn++8qCq AgUNHiggqIcz8s872QxEDkk/ETICx7ViY4eaxAU+jjce9Hvo2Lj0S+fzzqUKADPi sgINDCM0ePJWycWTjpjD86IP1H5mTPoJBHaK6KJom0/u7i8oa0SNlM2xuX8oXk5v YnLtS2rDpjsmfzWfLC9edUY= Received: (qmail 37490 invoked by alias); 21 May 2019 14:22:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 37453 invoked by uid 89); 21 May 2019 14:22:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:POINTER X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 May 2019 14:22:50 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 29FDBAE0C for ; Tue, 21 May 2019 14:22:48 +0000 (UTC) Date: Tue, 21 May 2019 16:22:47 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Handle ABS_EXPR in rewrite_to_defined_overflow Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following makes us properly rewrite ABS_EXPR to avoid undefined overflow when hoisting it from a not always executed region. Bootstrap & regtest on x86_64-unknown-linux-gnu in progress. Richard. 2019-05-21 Richard Biener * gimple-fold.c (arith_code_with_undefined_signed_overflow): Add ABS_EXPR. (rewrite_to_defined_overflow): Handle rewriting ABS_EXPR as ABSU_EXPR. * gcc.dg/tree-ssa/ssa-lim-13.c: New testcase. Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 271463) +++ gcc/gimple-fold.c (working copy) @@ -7329,6 +7329,7 @@ arith_code_with_undefined_signed_overflo { switch (code) { + case ABS_EXPR: case PLUS_EXPR: case MINUS_EXPR: case MULT_EXPR: @@ -7361,12 +7362,15 @@ rewrite_to_defined_overflow (gimple *stm tree lhs = gimple_assign_lhs (stmt); tree type = unsigned_type_for (TREE_TYPE (lhs)); gimple_seq stmts = NULL; - for (unsigned i = 1; i < gimple_num_ops (stmt); ++i) - { - tree op = gimple_op (stmt, i); - op = gimple_convert (&stmts, type, op); - gimple_set_op (stmt, i, op); - } + if (gimple_assign_rhs_code (stmt) == ABS_EXPR) + gimple_assign_set_rhs_code (stmt, ABSU_EXPR); + else + for (unsigned i = 1; i < gimple_num_ops (stmt); ++i) + { + tree op = gimple_op (stmt, i); + op = gimple_convert (&stmts, type, op); + gimple_set_op (stmt, i, op); + } gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt)); if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR) gimple_assign_set_rhs_code (stmt, PLUS_EXPR); Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c (nonexistent) +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c (working copy) @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -fdump-tree-lim2-details" } */ + +int __GIMPLE (ssa,startwith("lim")) +foo (int x, int n) +{ + int i; + int r; + int _1; + int _2; + int _6; + + __BB(2): + goto __BB7; + + __BB(3): + if (i_5 == 17) + goto __BB8; + else + goto __BB4; + + __BB(4): + _1 = i_5 & 1; + if (_1 != 0) + goto __BB5; + else + goto __BB6; + + __BB(5): + _2 = __ABS x_8(D); + r_9 = _2 / 5; + goto __BB6; + + __BB(6): + r_3 = __PHI (__BB5: r_9, __BB4: r_4); + i_10 = i_5 + 1; + goto __BB7; + + __BB(7,loop_header(1)): + r_4 = __PHI (__BB2: 1, __BB6: r_3); + i_5 = __PHI (__BB2: 0, __BB6: i_10); + if (i_5 < n_7(D)) + goto __BB3; + else + goto __BB8; + + __BB(8): + _6 = __PHI (__BB3: 0, __BB7: r_4); + return _6; +} + +/* { dg-final { scan-tree-dump-times "Moving statement" 2 "lim2" } } */ +/* { dg-final { scan-tree-dump "ABSU_EXPR" "lim2" } } */