From patchwork Wed Apr 12 09:29:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9676911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B026F60381 for ; Wed, 12 Apr 2017 09:31:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1547285C8 for ; Wed, 12 Apr 2017 09:31:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96380285D2; Wed, 12 Apr 2017 09:31:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15D46285C8 for ; Wed, 12 Apr 2017 09:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752236AbdDLJbg (ORCPT ); Wed, 12 Apr 2017 05:31:36 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33093 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751054AbdDLJbf (ORCPT ); Wed, 12 Apr 2017 05:31:35 -0400 Received: by mail-wm0-f68.google.com with SMTP id o81so5165196wmb.0 for ; Wed, 12 Apr 2017 02:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jlLIn86FYY92+3zwLPAPJXjEPP5iMbZIYjaV7sMjbow=; b=OVZWWoZ0fxGAL3KE0AgIKrreu1RO8q0AT3yAzK4zYr4jOO1rA8cqvafrTqTtJuNu2L PllYVbakD6FYAMCrYx879ZZ85N7ge021ehPs0dqybusmAzdThQYGtGWzhLuC/xNpvuur josS8C2N/1X5h55tGDeZbXyWZ4F058+y6n+K9g1/TkvNGOigeHKp2ET9epwD7vUICMfH 4SB8vutbPl5NygCDbZZSQBvCsKjwrOStuv4U6Uj1WL3gQ1sVneCZXm3eB5AnlnZoxyoX 3hIS+LAq3auUR7LqlSMgb5gv88IK+muip1CtxLvokLyqioI4lsHVtz3GXNPAmi5Qywax XilQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jlLIn86FYY92+3zwLPAPJXjEPP5iMbZIYjaV7sMjbow=; b=MfFtQQ8x86TR4GGr6A3esYSTFuSuyFssQl0qIlnLPoxwlZC4+6F/x42tZMcX5bo5qt TyrHzNhmo52Mkbp5vBsRL+diRqcwLr4yeETrN5j1gudsAGFESq/9+boIfX59qpF1BOEz QW5SFOSotLiX+PDLmrZ6jNNwbdzJ7e0F39jqy8R6BZ7PKTAuqtcO3Owr3OvAIiwSBRzB SCaMbQmCf83YFfSjDvJqImg1cwa/g5GeSlHiKFouvhW4Yz2XlsiEUgZsy6aall7fKQ7i YujWLIIJ671cQApPp922/ER/OcCwvWetLSw7+0Y00TWUO8FRm2XEOMPCnj0vpmfZvSrK scqA== X-Gm-Message-State: AN3rC/7r5ZV1hd2EWIw4OgaJf7Xgg00tZajeEX9VPUBjmqzPh1rMKJzc eEVOTEpskspzgX3/oLQ= X-Received: by 10.28.170.148 with SMTP id t142mr18666579wme.57.1491989493948; Wed, 12 Apr 2017 02:31:33 -0700 (PDT) Received: from localhost.localdomain ([91.177.93.162]) by smtp.gmail.com with ESMTPSA id a10sm24992281wra.17.2017.04.12.02.31.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 02:31:33 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 2/2] CSE: support CSE of floating-point literal Date: Wed, 12 Apr 2017 11:29:27 +0200 Message-Id: <20170412092927.23884-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170412092927.23884-1-luc.vanoostenryck@gmail.com> References: <20170412092927.23884-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before the introduction of OP_SETFVAL, floating-point were created via OP_SETVAL whose CSE is done by comparing the pointer of the corresponding expression without any interpretation of this pointer. As consequence, even if two OP_SETVAL have two identical expressions (value), in most cases the corresponding pointers are not identical, completly inhibiting the CSE of OP_SETVALs. Fix the CSE of floating-point literals by directly using the value given by the new OP_SETFVAL. Note: to respect some of the subtilities of floating-point, the equality comparison of two literals is not done on the floating-point value itself but bit-by-bit on its binary representation (as such we can continue to make the distinction between +0.0 & -0.0, handle NaNs, ...). Signed-off-by: Luc Van Oostenryck --- cse.c | 11 +++++++++++ validation/optim/cse-setfval.c | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 validation/optim/cse-setfval.c diff --git a/cse.c b/cse.c index f535636b4..cd1e8942c 100644 --- a/cse.c +++ b/cse.c @@ -89,6 +89,10 @@ static void clean_up_one_instruction(struct basic_block *bb, struct instruction hash += hashval(insn->val); break; + case OP_SETFVAL: + hash += hashval(insn->fvalue); + break; + case OP_SYMADDR: hash += hashval(insn->symbol); break; @@ -178,6 +182,7 @@ static int insn_compare(const void *_i1, const void *_i2) { const struct instruction *i1 = _i1; const struct instruction *i2 = _i2; + int diff; if (i1->opcode != i2->opcode) return i1->opcode < i2->opcode ? -1 : 1; @@ -240,6 +245,12 @@ static int insn_compare(const void *_i1, const void *_i2) return i1->val < i2->val ? -1 : 1; break; + case OP_SETFVAL: + diff = memcmp(&i1->fvalue, &i2->fvalue, sizeof(i1->fvalue)); + if (diff) + return diff; + break; + /* Other */ case OP_PHI: return phi_list_compare(i1->phi_list, i2->phi_list); diff --git a/validation/optim/cse-setfval.c b/validation/optim/cse-setfval.c new file mode 100644 index 000000000..59c00a407 --- /dev/null +++ b/validation/optim/cse-setfval.c @@ -0,0 +1,12 @@ +int ftest(double a, double b) +{ + return a == 0.125 || b == 0.125; +} + +/* + * check-name: CSE OP_SETFVAL + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern-1-times: setfval\\. + */