From patchwork Fri Aug 19 02:09:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 74209 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp85246qga; Thu, 18 Aug 2016 19:10:24 -0700 (PDT) X-Received: by 10.66.181.139 with SMTP id dw11mr9403769pac.2.1471572624009; Thu, 18 Aug 2016 19:10:24 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id wh1si5433531pab.238.2016.08.18.19.10.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Aug 2016 19:10:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-434256-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-434256-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-434256-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=k311dBastqNO0ubYqe50A4I68thFmKEOsAVV5g9PiRp03u FIzYGymN7KUPlOBKd5iiNCaJWJtBpAFYgH0AUdjy90/8Mb8KJAX0VFBa8XpcbP5c 0oVAHGK3IGNql2z0FJBwX9R7e5wrw/Rh6DmtA2KdiE+HYqmZ6XN+B2oHyi1Ns= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=ZdJDNBVjV8YfAr2krsQ+woIcxdM=; b=fX8WXTlh2qIe+ESQjb4E pOnux9ntPAvr5/iyVa3B98SyVv6V2/S2ScN1leAdk5ACO/HjPmY9oG1dXvgznxAF JzX92LKAkqI+sRuJMamCZrlUa6jRab9AimQA1GMNpyhw0W/6YSyeHbG8dWkYUor3 xp+aJU0V5HeNoR/L0lT+V+s= Received: (qmail 22310 invoked by alias); 19 Aug 2016 02:10:08 -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 22154 invoked by uid 89); 19 Aug 2016 02:10:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Possible, UD:value, Hx-languages-length:3169 X-HELO: mail-qk0-f170.google.com Received: from mail-qk0-f170.google.com (HELO mail-qk0-f170.google.com) (209.85.220.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Aug 2016 02:09:56 +0000 Received: by mail-qk0-f170.google.com with SMTP id v123so34324174qkh.2 for ; Thu, 18 Aug 2016 19:09:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=J3Wc0fb9S6ODyZWtuQBWgY2V4F4xK13VIDYzajD7oMs=; b=FxZeACORDHgb7ixAEXBoiWTZKw+ioEkywAXqBH1x9Otvb9YrLbxzpo3ymfz+lr63j1 OUeHIS3sTgc/7ynMzqaeWEAHGHSDLFZisRbUu4s8fznfiu2nU+jisFCvv9I4aoVeYOI7 MgDFB+791/mMi5RPN+7MbmkZMSVJmZIznlZnPiaFsAFRcwk/esEQrrzYGvwzLS8M2S8o 7/t4uQifkQagut+WyhnvQSVHiMSYFZAagT8A/39eMT5+vLKOEia1gmp0rL0BhYwcF3UH gAUcM2JguZJIDiUMwkpje4V2s+7j/ZoEfoB5T0km++8RIip9VDYvJDGswO+hKdy543Yw X2pw== X-Gm-Message-State: AEkoouuHFjkL06mN0omAgieqyWXgd2PGB9DGKrnmYg229cX4iZIcyNdUo5+4qCfSUVdmbqgnHMP0Ws02U0ZKhXia X-Received: by 10.55.207.137 with SMTP id v9mr6046056qkl.248.1471572595108; Thu, 18 Aug 2016 19:09:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.53.49 with HTTP; Thu, 18 Aug 2016 19:09:54 -0700 (PDT) From: Kugan Vivekanandarajah Date: Fri, 19 Aug 2016 12:09:54 +1000 Message-ID: Subject: [TREE-SSA-CCP] Issue warning when folding condition To: "gcc-patches@gcc.gnu.org" , Richard Biener , Jeff Law X-IsSubscribed: yes The testcase pr33738.C for warning fails with early-vrp patch. The reason is, with early-vrp ccp2 is folding the comparison that used to be folded in simplify_stmt_for_jump_threading. Since early-vrp does not perform jump-threading is not optimized there. Attached patch adds this warning to tree-ssa-ccp.c. We might also run into some other similar issues in the future. Bootstrapped and regression tested on x86_64-linux-gnu with no new regressions. Is this OK for trunk? Thanks, Kugan gcc/ChangeLog: 2016-08-18 Kugan Vivekanandarajah * tree-ssa-ccp.c (ccp_fold_stmt): If the comparison is being folded and the operand on the LHS is being compared against a constant value that is outside of type limit, issue warning. >From 62152b5499233c2136dc388fd0322bab999f0cb4 Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Thu, 18 Aug 2016 20:29:38 +1000 Subject: [PATCH 7/7] Add warn_type_limits to ccp --- gcc/tree-ssa-ccp.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 5d5386e..3c32045 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -142,6 +142,8 @@ along with GCC; see the file COPYING3. If not see #include "cfgloop.h" #include "stor-layout.h" #include "optabs-query.h" +#include "diagnostic-core.h" +#include "intl.h" /* Possible lattice values. */ @@ -2147,7 +2149,11 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi) case GIMPLE_COND: { gcond *cond_stmt = as_a (stmt); + tree lhs = gimple_cond_lhs (stmt); + tree rhs = gimple_cond_rhs (stmt); ccp_prop_value_t val; + wide_int min, max, rhs_val; + bool warn_limit = false; /* Statement evaluation will handle type mismatches in constants more gracefully than the final propagation. This allows us to fold more conditionals here. */ @@ -2165,6 +2171,41 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi) fprintf (dump_file, "\n"); } + /* If the comparison is being folded and the operand on the LHS + is being compared against a constant value that is outside of + the natural range of LHSs type, then the predicate will + always fold regardless of the value of LHS. If -Wtype-limits + was specified, emit a warning. */ + if (warn_type_limits + && INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + && (rhs = get_constant_value (rhs)) + && (TREE-code (rhs) == INTEGER_CST)) + { + rhs_val = rhs; + min = TYPE_MIN_VALUE (TREE_TYPE (lhs)); + max = TYPE_MAX_VALUE (TREE_TYPE (lhs)); + warn_limit = true; + } + + if (warn_limit + && (wi::cmp (rhs_val, min, TYPE_SIGN (TREE_TYPE (lhs))) == -1 + || wi::cmp (max, rhs_val, TYPE_SIGN (TREE_TYPE (lhs))) == -1)) + { + location_t location; + + if (!gimple_has_location (stmt)) + location = input_location; + else + location = gimple_location (stmt); + + warning_at (location, OPT_Wtype_limits, + integer_zerop (val.value) + ? G_("comparison always false " + "due to limited range of data type") + : G_("comparison always true " + "due to limited range of data type")); + } + if (integer_zerop (val.value)) gimple_cond_make_false (cond_stmt); else -- 2.7.4