From patchwork Mon Feb 10 16:55:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1235887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519250-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=B3wdZ6+U; 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 48GX971b7Mz9sRL for ; Tue, 11 Feb 2020 03:55:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=VGt+mfH17FJ26Ltu 3NVBwi9n8s7/IN3Z2BZvjLGjtC9f2Ne4Pnzuz9NDrprLnOdlHMkF6XUSP9Fi2sM+ HsbBWLe1xjYAwqj0ysYzcp0yYBS9V2dUdBjdZETcHd6wEI5kjkOj/ITJsyuuyH5t hFFoKDeJApIWukSbcb6qNoCESQ8= 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 :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=rjfxSBpraddVRVcUKy6eBG /rQog=; b=B3wdZ6+UrQasXl79ko6C/hjjatc0//Oxe54++TduaOfWVVuaI2kzFh HLPD6IGxWsuMQpeoaZf5qFFD2WzFFTgC1hheaZHBPb/bg5tz1Rm8U/BoMTmO2nWY 7aIWRtGzuFmt0tsTFmasF2dBqM5E07M16GD+eJ+aFtPk3oX0v/pQY= Received: (qmail 35859 invoked by alias); 10 Feb 2020 16:55:46 -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 35848 invoked by uid 89); 10 Feb 2020 16:55:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: smtp1.axis.com Received: from smtp1.axis.com (HELO smtp1.axis.com) (195.60.68.17) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Feb 2020 16:55:44 +0000 IronPort-SDR: VpkkcduEmuBTkKh5UohfETnLBFvQnhUD6uFWP7tw5CByWneji91XJf7kCvlSByBAGCWTlvgca0 M7wtqK0myLbRD1HsqRt/hWqvNfKWGkNg8yiFpKjIpn1iPM/9Zo6SEZUwVkFREk50cqxkQaKGh/ VAAOI01OxAEDQv3EMswo+maEG8UvQr7DSc2lW4RAl4//XhxYpmQLF8aEThlKTrvzJQuR+HTHck M4JDBaYv5+9mlZD2L1EQfDIMfznYKr7713Of5WU0f8rwl7ophSxypsPz59OoMv+tKm5riNNOd8 zSA= Date: Mon, 10 Feb 2020 17:55:41 +0100 Message-ID: <202002101655.01AGtfek012447@ignucius.se.axis.com> From: Hans-Peter Nilsson To: Subject: [1/6 CRIS cc0-preparations] try to generate zero-based comparisons MIME-Version: 1.0 X-IsSubscribed: yes * config/cris/cris.c (cris_reduce_compare): New function. * config/cris/cris-protos.h (cris_reduce_compare): Add prototype. * config/cris/cris.md ("cbranch4", "cbranchdi4", "cstoredi4") (cstore4"): Apply cris_reduce_compare in expanders. The decc0ration work of the CRIS port made me look closer at the code for trivial comparisons, as in the condition for branches and conditional-stores, like in: void g(short int a, short int b) { short int c = a + b; if (c >= 0) foo (); } At -O2, the cc0 version of the CRIS port has an explicit *uneliminated* compare instruction ("cmp.w -1,$r10") instead of an (eliminated) compare against 0 (which below I'll call a zero-compare). This for the CRIS-cc0 version, but I see this also for a much older gcc, at 4.7. For the decc0rated port, the compare *is* a test against 0, eventually eliminated. To wit, for cc0 (mind the delay-slot): _g: subq 4,$sp add.w $r11,$r10 cmp.w -1,$r10 ble .L9 move $srp,[$sp] jsr _foo .L9: jump [$sp+] The compare instruction is expected to be eliminated, i.e. the following diff to the above is desired, modulo the missing sibling call, which corresponds to what I get from 4.7 and for the decc0rated port: !--- a Wed Feb 5 15:22:27 2020 !+++ b Wed Feb 5 15:22:51 2020 !@@ -1,8 +1,7 @@ ! _g: ! subq 4,$sp ! add.w $r11,$r10 !- cmp.w -1,$r10 !- ble .L9 !+ bmi .L9 ! move $srp,[$sp] ! ! jsr _foo Tracking this difference, I see that for both cc0-CRIS and the decc0rated CRIS, the comparison actually starts out as a compare against -1 at "expand" time, but is transformed for decc0rated CRIS to a zero-compare in "cse1". For CRIS-cc0 "cse1" does try to replace the compare with a zero-compare, but fails because at the same time it tries to replace the c operand with (a + b). Or some such; it fails and no other pass succeeds. I was not into fixing cc0-handling in core gcc, so I didn't look closer. BTW, at first, I was a bit surprised to see that for compares against a constant, a zero-compare is not canonical RTX for *all* conditions, and that instead only a subset of all RTX conditions against a constant are canonical, transforming one condition to the canonical one by adding 1 or -1 to the constant. It does makes sense at a closer look, but still not so much when emitting RTL. There are several places that mention in comments that emitting RTX as zero-compare is preferable, but nothing is done about it. Some generic code instead seems confused that the *target* is helped by seeing canonical RTX, or perhaps it (its authors) like me, confused about what a canonical comparison is. For example, prepare_cmp_insn calls canonicalize_comparison last before emitting the actual instructions. I see most ports for various port-specific reasons does their own massaging in their cbranch and cstore expanders. Still, the suboptimal compares *should* be fixed at expand time; better start out right than just relying on later optimizations. This kind of change is not acceptable in the current gcc development stage, at least as a change in generic code. However, it's problematic enough that I chose to fix this right now in the CRIS port. For that, I claim a possibly long-standing regression. After this, code before and after decc0ration is similar enough that I can spot compare-elimination-efforts and apply regression test-cases without them drowning in cc0-specific xfailing. I hope to eventually lift out cris_reduce_compare (renamed) into say expmed.c, called in e.g. emit_store_flag_1 (replacing the in-line code) and prepare_cmp_insn. Later. --- gcc/config/cris/cris-protos.h | 1 + gcc/config/cris/cris.c | 57 +++++++++++++++++++++++++++++++++++++++++++ gcc/config/cris/cris.md | 6 +++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/gcc/config/cris/cris-protos.h b/gcc/config/cris/cris-protos.h index 2105256cc..6f6d81567 100644 --- a/gcc/config/cris/cris-protos.h +++ b/gcc/config/cris/cris-protos.h @@ -38,6 +38,7 @@ extern bool cris_constant_index_p (const_rtx); extern bool cris_base_p (const_rtx, bool); extern bool cris_base_or_autoincr_p (const_rtx, bool); extern bool cris_bdap_index_p (const_rtx, bool); +extern void cris_reduce_compare (rtx *, rtx *, rtx *); extern bool cris_biap_index_p (const_rtx, bool); extern bool cris_legitimate_address_p (machine_mode, rtx, bool); extern bool cris_store_multiple_op_p (rtx); diff --git a/gcc/config/cris/cris.c b/gcc/config/cris/cris.c index 01388b3d0..91cb63c01 100644 --- a/gcc/config/cris/cris.c +++ b/gcc/config/cris/cris.c @@ -3053,6 +3053,63 @@ cris_split_movdx (rtx *operands) return val; } +/* Try to change a comparison against a constant to be against zero, and + an unsigned compare against zero to be an equality test. Beware: + only valid for compares of integer-type operands. Also, note that we + don't use operand 0 at the moment. */ + +void +cris_reduce_compare (rtx *relp, rtx *, rtx *op1p) +{ + rtx op1 = *op1p; + rtx_code code = GET_CODE (*relp); + + /* Code lifted mostly from emit_store_flag_1. */ + switch (code) + { + case LT: + if (op1 == const1_rtx) + code = LE; + break; + case LE: + if (op1 == constm1_rtx) + code = LT; + break; + case GE: + if (op1 == const1_rtx) + code = GT; + break; + case GT: + if (op1 == constm1_rtx) + code = GE; + break; + case GEU: + if (op1 == const1_rtx) + code = NE; + break; + case LTU: + if (op1 == const1_rtx) + code = EQ; + break; + case GTU: + if (op1 == const0_rtx) + code = NE; + break; + case LEU: + if (op1 == const0_rtx) + code = EQ; + break; + default: + break; + } + + if (code != GET_CODE (*relp)) + { + *op1p = const0_rtx; + PUT_CODE (*relp, code); + } +} + /* The expander for the prologue pattern name. */ void diff --git a/gcc/config/cris/cris.md b/gcc/config/cris/cris.md index b73ea8bb7..fd8355c23 100644 --- a/gcc/config/cris/cris.md +++ b/gcc/config/cris/cris.md @@ -3539,7 +3539,7 @@ (define_expand "cbranch4" (label_ref (match_operand 3 "" "")) (pc)))] "" - "") + "cris_reduce_compare (&operands[0], &operands[1], &operands[2]);") (define_expand "cbranchdi4" [(set (cc0) @@ -3552,6 +3552,7 @@ (define_expand "cbranchdi4" (pc)))] "" { + cris_reduce_compare (&operands[0], &operands[1], &operands[2]); if (TARGET_V32 && !REG_P (operands[1])) operands[1] = force_reg (DImode, operands[1]); if (TARGET_V32 && MEM_P (operands[2])) @@ -3652,6 +3653,7 @@ (define_expand "cstoredi4" [(cc0) (const_int 0)]))] "" { + cris_reduce_compare (&operands[1], &operands[2], &operands[3]); if (TARGET_V32 && !REG_P (operands[2])) operands[2] = force_reg (DImode, operands[2]); if (TARGET_V32 && MEM_P (operands[3])) @@ -3666,7 +3668,7 @@ (define_expand "cstore4" (match_operator:SI 1 "ordered_comparison_operator" [(cc0) (const_int 0)]))] "" - "") + "cris_reduce_compare (&operands[1], &operands[2], &operands[3]);") ;; Like bCC, we have to check the overflow bit for ;; signed conditions. From patchwork Mon Feb 10 16:57:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1235890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519251-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=ZI/LgMYk; 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 48GXBt6JqKz9sP7 for ; Tue, 11 Feb 2020 03:57:25 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=QDKksF5/XaFcPpxL ULf45BThQd8fZwr/ztwUJIIepXwO+xmYvzmyod41vQ0EBiqPdWv0xjulaaZAJ4O7 yx3hSRXNVlfvElf1fOEiBt9cKaVt8B/pREx3yGR0UM4Z/iv5eyNGKIzYmezWNNWC abiAo1cmXsF+AmEb9ppHvDiz/20= 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 :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=di4TtJR8axiruQw/TQQfNV 6Hl64=; b=ZI/LgMYkDz3aEagvZkxSE/ivWyq/AjZmKSmourFKt3MAlw3CEm1X3s AmYYCyhJqVb0meVodoJYxrGEOPuCEBddmdvwg9uMovc/xU2XWCiK+tHXuil/ZZs1 /DOY9a5SRUT37NXRn2A7Kbfx6cmalJJQMIuHj5xNCrahPueUze5nc= Received: (qmail 40814 invoked by alias); 10 Feb 2020 16:57:18 -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 40806 invoked by uid 89); 10 Feb 2020 16:57:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: smtp1.axis.com Received: from smtp1.axis.com (HELO smtp1.axis.com) (195.60.68.17) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Feb 2020 16:57:17 +0000 IronPort-SDR: tFAlcaWTv5q31i4lagH5qa4I3LGSoux/vA082suon/xKL1HZnNwrXMtgecZ2wDP236gJ0UGjmL 7WsS5BVeaOcPDOuLmsA24usYk5pCdhHiUbt62Kkg8Pg61mnmUA1I+5GtG52MgsvNi5dLFVZGfh 9wAo18Uumy4m2AAcuzbNLKJ2+pD5ZrQsNz7+0T5QEtF3HlJ4rOOvqDAUB4dwTm4MRnJb65uASJ J3ZKo2W/Cl6vmG0OVcXShzxiFyYSoYp74UytCdL9SZw+Waux6tJvjsKg5YZjlk1+sOXtqsHrFd re0= Date: Mon, 10 Feb 2020 17:57:14 +0100 Message-ID: <202002101657.01AGvEtM012521@ignucius.se.axis.com> From: Hans-Peter Nilsson To: Subject: [2/6 CRIS cc0-preparations] gcc.target/cris/cris.exp (check_effective_target_cc0): New. MIME-Version: 1.0 X-IsSubscribed: yes To simplify separating the cc0-specific xfails, let's have an effective-target. This likely fits all targets. --- gcc/testsuite/gcc.target/cris/cris.exp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gcc/testsuite/gcc.target/cris/cris.exp b/gcc/testsuite/gcc.target/cris/cris.exp index c85c849e8..52164514d 100644 --- a/gcc/testsuite/gcc.target/cris/cris.exp +++ b/gcc/testsuite/gcc.target/cris/cris.exp @@ -25,6 +25,17 @@ if { ![istarget cris-*-*] && ![istarget crisv32-*-*] } then { # Load support procs. load_lib gcc-dg.exp +# For the time being, provide a means to tell whether the target is "cc0". +# Some targets may split cbranch and cstore late, but for a cc0-target, +# all the fun happens at "final" time, so this should be a safe time for +# a scan. +proc check_effective_target_cc0 { } { + return [check_no_messages_and_pattern cc0 "\\(cc0\\)" rtl-final { + extern void g (void); + void f (int *p, int *q) { *q = *p == 42; if (*p == 7) g (); } + }] +} + # If a testcase doesn't have special options, use these. global DEFAULT_CFLAGS if ![info exists DEFAULT_CFLAGS] then { From patchwork Mon Feb 10 16:58:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1235891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519252-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=HiXkWiPb; 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 48GXDD0Xs4z9sRL for ; Tue, 11 Feb 2020 03:58:35 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=sMP3XvRNV3PEavHe +Q/FBXMW+V1RfPDC+CaZ5YZZp/q/zAHmqtGDk1LdwPXkh0ThqZy82dTUusZd6WN9 boFQFHdsj6eGeU2YeEqYsWoglTUz2Jl8vHi08RPZl4mja22ofj6NkLRepfJmM0mv W/VQFtPJdv/KS7VZKR5jba1o7E0= 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 :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=5dwWyrbiCsCBEZIToJa0XN q03z4=; b=HiXkWiPbFc64xQOYzK70rkyn04Bb5BD08uXxGNPD/wAPX2wBDEHSuc 3caA92E4+l0rtwIik1A06WF9TqQwTV80FC4VZ08TpybUIleiCBQmX1vTrRs4cINi kUhWB0PRVzSZD74mQWb9j6TL20GSDZTa+B6SAOqxGqFCNdqyXTReg= Received: (qmail 43831 invoked by alias); 10 Feb 2020 16:58:28 -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 43823 invoked by uid 89); 10 Feb 2020 16:58:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: smtp2.axis.com Received: from smtp2.axis.com (HELO smtp2.axis.com) (195.60.68.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Feb 2020 16:58:26 +0000 IronPort-SDR: kVdzuATP04Ja8FnYmORgKYniLMamL3mSrzg1yLkX2vmU+/Ucb0nVcDNj2XyQ5pA6EmN6npOGMq BNj6AgK771PPKfEuQM9lz5oBa7Zs9Pmjh9o3otIwfDfzPdEw+wqP+6TU+QJthxO79SxxPIL5GI XaxBjCkHuzqxne1aWjDsY4g9kggIRXYCx44iE8i1LHdJe3tjqzV6BsXHPx9W8DuUuLXbpdVEvo P9ve6JtWDTjUlTwScUCxkcR3Xx39ekEIgCpHRwsFxJ5nVbX//7nYc7SwfOiyjJO/iD9faFH/JM XGQ= Date: Mon, 10 Feb 2020 17:58:23 +0100 Message-ID: <202002101658.01AGwNsU012586@ignucius.se.axis.com> From: Hans-Peter Nilsson To: Subject: [3/6 CRIS cc0-preparations] gcc.target/cris/pr93372-1.c: New test. MIME-Version: 1.0 X-IsSubscribed: yes This test was separated from the posted and approved patch named "dbr: Filter-out TARGET_FLAGS_REGNUM from end_of_function_needs" and applied: it doesn't fail yet. It differs from the posted version in that function "g" is commented-out; see the added comment. --- gcc/testsuite/gcc.target/cris/pr93372-1.c | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-1.c diff --git a/gcc/testsuite/gcc.target/cris/pr93372-1.c b/gcc/testsuite/gcc.target/cris/pr93372-1.c new file mode 100644 index 000000000..20aa65e8d --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-1.c @@ -0,0 +1,72 @@ +/* Check that all more-or-less trivially fillable delayed-branch-slots + are filled. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tnop" } } */ + +void *f(void **p) +{ + /* Supposedly the memory read finds its way into the "ret" + delay-slot. */ + return *p; +} + +#if 0 +/* Until the negative effects of g:897a73086b2 a.k.a. r10-6395 + a.k.a. "One more fix for PR 91333 - suboptimal register allocation + for inline asm", which appears to have caused a "nop" (unfilled + delay-slot) to appear for this function for CRIS-decc0rated (but not + CRIS-cc0) and increasing one execution-path by one instruction (and + the size of the whole function), it's left out. It was but a mere + attempt to expose the flaw better noticed with xlshrdi3. It exposes + a real issue, just less important. FIXME: extract to separate test. */ +int g(int *x, int *y, char *v, int n) +{ + int z = *x; + int w = *v + 31; + + /* Two branch and two return slots, all filled. */ + if (z != 23 && z != n+1) + return *x+*y+24+w; + return *y+24+w; +} +#endif + +/* No problem with the two examples above, but with a more involved + example, the epilogue contents matter (the condition-code register + clobber was mistaken for a register that needed to be alive). */ + +struct DWstruct {int low, high;}; +typedef unsigned long long DItype; +typedef unsigned int USItype; + +typedef union +{ + struct DWstruct s; + DItype ll; +} DWunion; + +unsigned long long +xlshrdi3 (DItype u, unsigned int b) +{ + if (b == 0) + return u; + + const DWunion uu = {.ll = u}; + const int bm = (4 * 8) - b; + DWunion w; + + if (bm <= 0) + { + w.s.high = 0; + w.s.low = (USItype) uu.s.high >> -bm; + } + else + { + const USItype carries = (USItype) uu.s.high << bm; + w.s.high = (USItype) uu.s.high >> b; + w.s.low = ((USItype) uu.s.low >> b) | carries; + } + + return w.ll; +} From patchwork Mon Feb 10 16:59:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1235893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519253-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=lenPxRY5; 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 48GXFL5pvyz9sP7 for ; Tue, 11 Feb 2020 03:59:33 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Oo9CAZbbaW7GlNIl BSfdbA9bVOu8wBqW5jIBlSLrRpcDCgl6k97YZrnXNSKh5eoeldg0ko6CsqEjMwJy wcPDqXU5XILMTV4IhYD+G+YVVrlP1HfCRkDe6XmkVl4gMgShqm7I6q+h0tV//rKf emTaft9djpdL7REQSrbhkdTAEr0= 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 :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=Y4naXGref/XcOVoPyreIqf iogWQ=; b=lenPxRY5GxI0bgxqhFnImEMNf5Mdh/MNwUuyJNcTcNoHOHkoO3IxGy TW0toJRd8rI5j+EoGjBNRqzT0snEWjx0T04lOczt0ZT62e115LBNSe0yOhaHwLnc yR1Se9wIvbvsRqljdJKfTaWnr5i94Q5TOXfgJOEo2Vu4Mrs/SiWU8= Received: (qmail 45561 invoked by alias); 10 Feb 2020 16:59:26 -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 45550 invoked by uid 89); 10 Feb 2020 16:59:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: smtp2.axis.com Received: from smtp2.axis.com (HELO smtp2.axis.com) (195.60.68.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Feb 2020 16:59:24 +0000 IronPort-SDR: FLpQNlZEbNXwb/V5x3J3n50W52Tops8xwv2BOXTG24QxpQLjfJepH0dkQeFA9ASBrkALL8iPk8 7oQQwPN88iiQhegUya+cudYOi2+AKG9TAn7IRKhRRxoepb42aVealPmLXvpObPU9c61sByVxcC RNH4mrsJHSi5/NVzlG3MFMaq4+Sco1eDPNX381/F+6Qqqj7QKNMQJ54B5J5Sa60boYSpeRZG9+ uGNNr3LMTS++95Ykzk0qVwU/iwdkqIMrvBGGNZCaUq0oj6ZRevHrBWsIKABpklzAYLgq8Q14iY fA8= Date: Mon, 10 Feb 2020 17:59:22 +0100 Message-ID: <202002101659.01AGxMff012654@ignucius.se.axis.com> From: Hans-Peter Nilsson To: Subject: [4/6 CRIS cc0-preparations] gcc.target/cris/pr93372-2.c, -5.c, -8.c: New tests. MIME-Version: 1.0 X-IsSubscribed: yes * gcc.target/cris/pr93372-2.c, gcc.target/cris/pr93372-5.c, gcc.target/cris/pr93372-8.c: New tests. These tests fails miserably both at being an example of cc0 eliminating compare instructions, and post-cc0-CRIS at showing a significant improvement. They're here to track suboptimal comparison code for CRIS. --- gcc/testsuite/gcc.target/cris/pr93372-2.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-5.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-8.c | 16 ++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-2.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-5.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-8.c diff --git a/gcc/testsuite/gcc.target/cris/pr93372-2.c b/gcc/testsuite/gcc.target/cris/pr93372-2.c new file mode 100644 index 000000000..912069c01 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-2.c @@ -0,0 +1,19 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" { xfail *-*-* } } } */ +/* { dg-final { scan-assembler-not "\tnot" { xfail cc0 } } } */ +/* { dg-final { scan-assembler-not "\tlsr" { xfail cc0 } } } */ + +int f(int a, int b, int *d) +{ + int c = a - b; + + /* Whoops! We get a cmp.d with the original operands here. */ + *d = (c == 0); + + /* Whoops! While we don't get a test.d for the result here for cc0, + we get a sequence of insns: a move, a "not" and a shift of the + subtraction-result, where a simple "spl" would have done. */ + return c >= 0; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-5.c b/gcc/testsuite/gcc.target/cris/pr93372-5.c new file mode 100644 index 000000000..351764c6c --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-5.c @@ -0,0 +1,19 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest|\tor" { xfail *-*-* } } } */ +/* { dg-final { scan-assembler-not "\tnot" { xfail cc0 } } } */ +/* { dg-final { scan-assembler-not "\tlsr" { xfail cc0 } } } */ + +int f(long long int a, long long int b, int *d) +{ + long long int c = a - b; + + *d = (c == 0LL); + + /* See pr93372-2.c; we have the same problem for DImode, but it's + worsened by the generic double-word "optimizations"; or:ing + together the DI parts and then testing the result for the equality + test. */ + return c >= 0LL; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-8.c b/gcc/testsuite/gcc.target/cris/pr93372-8.c new file mode 100644 index 000000000..95abc4b6b --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-8.c @@ -0,0 +1,16 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* See pr93372-5.c regarding the xfails. */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest|\tor" { xfail *-*-* } } } */ +/* { dg-final { scan-assembler-not "\tnot" { xfail cc0 } } } */ +/* { dg-final { scan-assembler-not "\tlsr" { xfail cc0 } } } */ + +int f(long long int a, long long int b, int *d) +{ + long long int c = a + b; + + *d = (c == 0); + + return c >= 0; +} From patchwork Mon Feb 10 17:00:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1235897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519254-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=ei2cWKhl; 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 48GXH34p4hz9sP7 for ; Tue, 11 Feb 2020 04:01:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=PTMrAdFCS4zr9bh3 EKhv5YAroqFxHk+muGBgzJDxwGzqkvWfgYyr5xy8uCOVMV325ge708VaLC3Fcjnq PCLbS6mk7VfVpSZW+STVR5TMxo+o0Hma8YFy16585DE6Qscw02KYfLQGcZoxIFOJ oSe71ak3hi/+8mq2/mOxAoSv0rk= 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 :message-id:from:to:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=RDVnlCJZPXFdm8+GArIZgG wixQ8=; b=ei2cWKhlilttGKdLEJJhuQ6oZRRkFM07+dhn8Idt0wXJOQOd+qar2m 2fpR4Vh415GYHZbziXVJRQ1ENZA1osBXAOkHZTOmZLEDiy4OANPmE7mz0ACns6oN walCdpb9qcw8Plq3+biSaq5OKDiJZZWEGuv42MIi59A6guoVcxyMA= Received: (qmail 48013 invoked by alias); 10 Feb 2020 17:00: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 47899 invoked by uid 89); 10 Feb 2020 17:00:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: smtp1.axis.com Received: from smtp1.axis.com (HELO smtp1.axis.com) (195.60.68.17) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Feb 2020 17:00:39 +0000 IronPort-SDR: ukgLFjUC5zcBf6uMa/GxZlf4XmhyeGt0rd51WEwF+coSqmiKdcN8UEV+NPf+E8tC63kfZIj+qJ RWuzZV6Mx4ZoMdvr48pFS/b1WAVGt+vMZt7VhBGr2JMf3gResV9OHNMA5J59AlIS+cK8kZ19TE +OQHtkVXtAWEmvXQ77NztchW4z4rpVuVAvjNGzitTGFTnG4KJ+F0CuG0Cb3fK1GtGzPO6IkNFd AQFl/E88Ae6jYY3m9pFdyIsp2BXCRRryY9e6OmYPCuf8VXm2Z4wP45D3cMqa1hUZlsR872M2/v ydI= Date: Mon, 10 Feb 2020 18:00:24 +0100 Message-ID: <202002101700.01AH0OjP012745@ignucius.se.axis.com> From: Hans-Peter Nilsson To: Subject: [5/6 CRIS cc0-preparations] gcc.target/cris/pr93372-3.c, -4.c...-35.c: New tests. MIME-Version: 1.0 X-IsSubscribed: yes PR target/93372 * gcc.target/cris/pr93372-3.c, gcc.target/cris/pr93372-4.c, gcc.target/cris/pr93372-6.c, gcc.target/cris/pr93372-7.c, gcc.target/cris/pr93372-9.c, gcc.target/cris/pr93372-10.c, gcc.target/cris/pr93372-11.c, gcc.target/cris/pr93372-12.c, gcc.target/cris/pr93372-13.c, gcc.target/cris/pr93372-14.c, gcc.target/cris/pr93372-15.c, gcc.target/cris/pr93372-16.c, gcc.target/cris/pr93372-17.c, gcc.target/cris/pr93372-18.c, gcc.target/cris/pr93372-19.c, gcc.target/cris/pr93372-20.c, gcc.target/cris/pr93372-21.c, gcc.target/cris/pr93372-22.c, gcc.target/cris/pr93372-23.c, gcc.target/cris/pr93372-24.c, gcc.target/cris/pr93372-25.c, gcc.target/cris/pr93372-26.c, gcc.target/cris/pr93372-27.c, gcc.target/cris/pr93372-28.c, gcc.target/cris/pr93372-29.c, gcc.target/cris/pr93372-30.c, gcc.target/cris/pr93372-31.c, gcc.target/cris/pr93372-32.c, gcc.target/cris/pr93372-33.c, gcc.target/cris/pr93372-34.c, gcc.target/cris/pr93372-35.c: New tests. Check that somewhat-trivially eliminable compare-instructions are eliminated, for all instructions. Note that pr93372-23.c and pr93372-24.c are xfailed with cc0. --- gcc/testsuite/gcc.target/cris/pr93372-10.c | 9 ++++ gcc/testsuite/gcc.target/cris/pr93372-11.c | 46 ++++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-12.c | 7 +++ gcc/testsuite/gcc.target/cris/pr93372-13.c | 18 +++++++ gcc/testsuite/gcc.target/cris/pr93372-14.c | 13 +++++ gcc/testsuite/gcc.target/cris/pr93372-15.c | 15 ++++++ gcc/testsuite/gcc.target/cris/pr93372-16.c | 42 +++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-17.c | 7 +++ gcc/testsuite/gcc.target/cris/pr93372-18.c | 24 +++++++++ gcc/testsuite/gcc.target/cris/pr93372-19.c | 8 +++ gcc/testsuite/gcc.target/cris/pr93372-20.c | 8 +++ gcc/testsuite/gcc.target/cris/pr93372-21.c | 8 +++ gcc/testsuite/gcc.target/cris/pr93372-22.c | 8 +++ gcc/testsuite/gcc.target/cris/pr93372-23.c | 21 ++++++++ gcc/testsuite/gcc.target/cris/pr93372-24.c | 19 +++++++ gcc/testsuite/gcc.target/cris/pr93372-25.c | 8 +++ gcc/testsuite/gcc.target/cris/pr93372-26.c | 7 +++ gcc/testsuite/gcc.target/cris/pr93372-27.c | 8 +++ gcc/testsuite/gcc.target/cris/pr93372-28.c | 8 +++ gcc/testsuite/gcc.target/cris/pr93372-29.c | 40 ++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-3.c | 15 ++++++ gcc/testsuite/gcc.target/cris/pr93372-30.c | 31 +++++++++++ gcc/testsuite/gcc.target/cris/pr93372-31.c | 33 ++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-32.c | 10 ++++ gcc/testsuite/gcc.target/cris/pr93372-33.c | 10 ++++ gcc/testsuite/gcc.target/cris/pr93372-34.c | 45 ++++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-35.c | 49 +++++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-4.c | 12 +++++ gcc/testsuite/gcc.target/cris/pr93372-6.c | 18 +++++++ gcc/testsuite/gcc.target/cris/pr93372-7.c | 85 ++++++++++++++++++++++++++++++ gcc/testsuite/gcc.target/cris/pr93372-9.c | 9 ++++ 31 files changed, 641 insertions(+) create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-10.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-11.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-12.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-13.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-14.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-15.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-16.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-17.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-18.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-19.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-20.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-21.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-22.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-23.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-24.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-25.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-26.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-27.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-28.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-29.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-3.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-30.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-31.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-32.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-33.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-34.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-35.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-4.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-6.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-7.c create mode 100644 gcc/testsuite/gcc.target/cris/pr93372-9.c diff --git a/gcc/testsuite/gcc.target/cris/pr93372-10.c b/gcc/testsuite/gcc.target/cris/pr93372-10.c new file mode 100644 index 000000000..76e8fef8d --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-10.c @@ -0,0 +1,9 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "\tcmp" 1 } } */ +/* { dg-final { scan-assembler-not "\ttest" } } */ + +#define t char +#include "pr93372-3.c" +#include "pr93372-7.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-11.c b/gcc/testsuite/gcc.target/cris/pr93372-11.c new file mode 100644 index 000000000..b5eb5ebb0 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-11.c @@ -0,0 +1,46 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#ifndef t +#define t short int +#endif +#ifndef t2 +#define t2 int +#endif + +#define eq_op(x) ((x) == 0) +#define ne_op(x) ((x) != 0) +#define gt_op(x) ((x) > 0) +#define gtu_op(x) ((x) > 0) +#define lt_op(x) ((x) < 0) +#define ltu_op(x) ((x) < 0) +#define ge_op(x) ((x) >= 0) +#define geu_op(x) ((x) >= 0) +#define le_op(x) ((x) <= 0) +#define leu_op(x) ((x) <= 0) + +#define f(n, T, T2) \ +T2 f ## n(T *a, T *b, T2 *d) \ +{ \ + T2 c = *a; \ + *d = c; \ + *b = n ## _op (c); \ + return c; \ +} + +f(eq, t, t2) +f(ne, t, t2) +f(gt, t, t2) +f(gtu, unsigned t, unsigned t2) +f(lt, t, t2) +#if 0 +f(ltu, unsigned t, unsigned t2) +#endif +f(ge, t, t2) +#if 0 +f(geu, t, t2) +#endif +f(le, t, t2) +f(leu, t, t2) diff --git a/gcc/testsuite/gcc.target/cris/pr93372-12.c b/gcc/testsuite/gcc.target/cris/pr93372-12.c new file mode 100644 index 000000000..429e0b849 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-12.c @@ -0,0 +1,7 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t char +#include "pr93372-11.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-13.c b/gcc/testsuite/gcc.target/cris/pr93372-13.c new file mode 100644 index 000000000..ff0d0f8a1 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-13.c @@ -0,0 +1,18 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest|\tor" } } */ + +extern void foo(void); + +void f(long long int a, long long int b) +{ + if (a + b == 0) + foo(); +} + +void g(long long int a, long long int b) +{ + if (a + b >= 0) + foo(); +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-14.c b/gcc/testsuite/gcc.target/cris/pr93372-14.c new file mode 100644 index 000000000..e0a846ee7 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-14.c @@ -0,0 +1,13 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "\tcmp|\ttest" 2 } } */ + +extern void foo(void); + +void f(long long int a, long long int b) +{ + /* Trivial check that we don't eliminate a non-eliminable compare. */ + if (a + b <= 0) + foo(); +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-15.c b/gcc/testsuite/gcc.target/cris/pr93372-15.c new file mode 100644 index 000000000..4932762af --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-15.c @@ -0,0 +1,15 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "\tcmp|\ttest" 1 } } */ + +int f(int a, int b, int *d) +{ + int c = a + b; + + *d = (c == 0); + + /* See also pr93372-6.c. We should get exactly one compare + instruction for this condition. */ + return c <= 0; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-16.c b/gcc/testsuite/gcc.target/cris/pr93372-16.c new file mode 100644 index 000000000..7e69d862c --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-16.c @@ -0,0 +1,42 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#ifndef t +#define t short int +#endif +#ifndef t2 +#define t2 t +#endif +#ifndef op +#define op + +#endif +#ifndef do_f +#define do_f 1 +#endif +#ifndef do_g +#define do_g 1 +#endif + +extern void foo(void); + +#if do_f +void f(t a, t b) +{ + t2 c = a op b; + + if (c == 0) + foo(); +} +#endif + +#if do_g +void g(t a, t b) +{ + t2 c = a op b; + + if (c >= 0) + foo(); +} +#endif diff --git a/gcc/testsuite/gcc.target/cris/pr93372-17.c b/gcc/testsuite/gcc.target/cris/pr93372-17.c new file mode 100644 index 000000000..05b5c31cc --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-17.c @@ -0,0 +1,7 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t signed char +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-18.c b/gcc/testsuite/gcc.target/cris/pr93372-18.c new file mode 100644 index 000000000..deb45e4f6 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-18.c @@ -0,0 +1,24 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest|\tor" } } */ + +#ifndef t +#define t long long +#endif +#ifndef t2 +#define t2 t +#endif +#ifndef op +#define op - +#endif + +extern void foo(t2); + +void g(t a, t b) +{ + t2 c = a op b; + + if (c >= 0) + foo(c); +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-19.c b/gcc/testsuite/gcc.target/cris/pr93372-19.c new file mode 100644 index 000000000..9a4e117d9 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-19.c @@ -0,0 +1,8 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t int +#define op - +#include "pr93372-18.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-20.c b/gcc/testsuite/gcc.target/cris/pr93372-20.c new file mode 100644 index 000000000..12870b368 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-20.c @@ -0,0 +1,8 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t short int +#define op - +#include "pr93372-18.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-21.c b/gcc/testsuite/gcc.target/cris/pr93372-21.c new file mode 100644 index 000000000..76845cb1a --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-21.c @@ -0,0 +1,8 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t signed char +#define op - +#include "pr93372-18.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-22.c b/gcc/testsuite/gcc.target/cris/pr93372-22.c new file mode 100644 index 000000000..23b38f6ee --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-22.c @@ -0,0 +1,8 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t int +#define op & +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-23.c b/gcc/testsuite/gcc.target/cris/pr93372-23.c new file mode 100644 index 000000000..fcefc9ab9 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-23.c @@ -0,0 +1,21 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ +/* For the f2, we want an andq, not and.w. */ +/* { dg-final { scan-assembler "\tandq 20," } } */ +/* { dg-final { scan-assembler-not "\tand.w 20," } } */ +/* We don't want a move.w that sets condition codes, but it happens for + cc0, as the "andq" that is the last insn before the branch, is for an + alternative that matches -32..31 and thus marked as clobbering + condition codes. */ +/* { dg-final { scan-assembler-not "\tmove.w" { xfail cc0 } } } */ + +#define op & +#include "pr93372-16.c" + +#undef op +#define op & 20 & +#define f f2 +#define g g2 +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-24.c b/gcc/testsuite/gcc.target/cris/pr93372-24.c new file mode 100644 index 000000000..87f10e93c --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-24.c @@ -0,0 +1,19 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ +/* For the f2, we want an andq, not and.b. */ +/* { dg-final { scan-assembler "\tandq 20," } } */ +/* { dg-final { scan-assembler-not "\tand.b 20," } } */ +/* See pr93372-23.c regarding the xfail. */ +/* { dg-final { scan-assembler-not "\tmove.b" { xfail cc0 } } } */ + +#define op & +#define t signed char +#include "pr93372-16.c" + +#undef op +#define op & 20 & +#define f f2 +#define g g2 +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-25.c b/gcc/testsuite/gcc.target/cris/pr93372-25.c new file mode 100644 index 000000000..448083b75 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-25.c @@ -0,0 +1,8 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t int +#define op | +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-26.c b/gcc/testsuite/gcc.target/cris/pr93372-26.c new file mode 100644 index 000000000..c44c918a8 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-26.c @@ -0,0 +1,7 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define op | +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-27.c b/gcc/testsuite/gcc.target/cris/pr93372-27.c new file mode 100644 index 000000000..38bfd9479 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-27.c @@ -0,0 +1,8 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define op | +#define t signed char +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-28.c b/gcc/testsuite/gcc.target/cris/pr93372-28.c new file mode 100644 index 000000000..3d32a7fa9 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-28.c @@ -0,0 +1,8 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define op ^ +#define t int +#include "pr93372-18.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-29.c b/gcc/testsuite/gcc.target/cris/pr93372-29.c new file mode 100644 index 000000000..7fb0fe8fb --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-29.c @@ -0,0 +1,40 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#ifndef t +#define t int +#endif +#ifndef t2 +#define t2 t +#endif +#ifndef op +#define op(x) ~(x) +#endif + +extern void foo(t2); + +t2 f(t a, t2 *b, t2 *d) +{ + t2 c = op(a); + + *b = c; + + if (c != 0) + *d = c; + + return c; +} + +t2 g(t a, t2 *b, t2 *d) +{ + t2 c = op(a); + + *b = c; + + if (c <= 0) + *d = c; + + return c; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-3.c b/gcc/testsuite/gcc.target/cris/pr93372-3.c new file mode 100644 index 000000000..c0fbdd83a --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-3.c @@ -0,0 +1,15 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "\tcmp" 1 } } */ + +#ifndef t +#define t int +#endif + +int ff(t a, t b, t *d) +{ + *d = (a == b); + + return a > b; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-30.c b/gcc/testsuite/gcc.target/cris/pr93372-30.c new file mode 100644 index 000000000..a61e8c42a --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-30.c @@ -0,0 +1,31 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#define t int +#define op >> +#define f ashrtf + +/* If we don't disable g, it will degenerate into a test of the + input. */ +#define do_g 0 + +#include "pr93372-16.c" +#undef do_g + +#undef t +#define t unsigned int +#undef f +#undef g +#define f lshrtf +#define g lshrtg +#include "pr93372-16.c" + +#undef f +#undef g +#undef op +#define op << +#define f shlf +#define g shlg +#include "pr93372-16.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-31.c b/gcc/testsuite/gcc.target/cris/pr93372-31.c new file mode 100644 index 000000000..649a90aa5 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-31.c @@ -0,0 +1,33 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-skip-if "" { "*-*-*" } { "-march=v0" } { "" } } */ +/* { dg-options "-O2" { target march_option } } */ +/* { dg-options "-O2 -march=v10" { target { ! march_option } } } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#ifndef t +#define t int +#endif +#ifndef t2 +#define t2 t +#endif +#ifndef t3 +#define t3 t +#endif +#ifndef op +#define op(xx) __builtin_clz(xx) +#endif + +extern t3 x; + +t2 f(t a, t2 *b, t2 *d) +{ + t2 c = op(a); + + *b = c; + + if (c != 0) + *d = c; + + return c; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-32.c b/gcc/testsuite/gcc.target/cris/pr93372-32.c new file mode 100644 index 000000000..64ab67895 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-32.c @@ -0,0 +1,10 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-skip-if "" { "*-*-*" } { "-march=*" } { "" } } */ +/* { dg-options "-O2 -march=v10" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ +/* { dg-final { scan-assembler "\tswapwb " } } */ + +#define op(xx) __builtin_bswap32(xx) + +#include "pr93372-31.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-33.c b/gcc/testsuite/gcc.target/cris/pr93372-33.c new file mode 100644 index 000000000..9c7d2ba93 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-33.c @@ -0,0 +1,10 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ +/* { dg-final { scan-assembler "\tbound" } } */ + +#define t unsigned int +#define op(xx) ((xx) < x ? (xx) : x) + +#include "pr93372-31.c" diff --git a/gcc/testsuite/gcc.target/cris/pr93372-34.c b/gcc/testsuite/gcc.target/cris/pr93372-34.c new file mode 100644 index 000000000..8bd3b4434 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-34.c @@ -0,0 +1,45 @@ +/* Check that btst/btstq other than a field starting at bit 0, is used. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tand" } } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ +/* { dg-final { scan-assembler-times "\tbtstq" 3 } } */ +/* { dg-final { scan-assembler-times "\tbtst " 3 } } */ + +void foo(void); + +void f(int *a) +{ + if ((*a & 32) != 0) + foo(); +} + +void g(short int *a) +{ + if ((*a & 128) == 0) + foo(); +} + +void h(char *a) +{ + if ((*a & 64) != 0) + foo(); +} + +void i(int *a, unsigned int n) +{ + if ((*a & (1 << n)) != 0) + foo(); +} + +void j(short int *a, unsigned int n) +{ + if ((*a & (1 << n)) == 0) + foo(); +} + +void k(char *a, unsigned int n) +{ + if ((*a & (1 << n)) != 0) + foo(); +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-35.c b/gcc/testsuite/gcc.target/cris/pr93372-35.c new file mode 100644 index 000000000..4e3649720 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-35.c @@ -0,0 +1,49 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ +/* { dg-final { scan-assembler "\tneg" } } */ + +void foo(void); + +#ifndef op +#define op(x) -(x) +#endif + +#define f(k, T, T2) \ +void f ## k (T *a, T2 *b) \ +{ \ + T2 d = op(*a); \ + *b = d; \ + if (d != 0) \ + foo(); \ +} + +#define ff(x, y) f(x, y, y) + +/* For NEG, gcc prefers to test the source (before the operation), but + will settle for the destination. For SImode, the destination is + allocated to a different register than the source. Not that + important; just skip the "int" variant for now. */ +#ifndef do_1 +#define do_1 0 +#endif + +#ifndef do_2 +#define do_2 1 +#endif +#ifndef do_3 +#define do_3 1 +#endif + +#if do_1 +ff(1, int) +#endif + +#if do_2 +ff(2, short int) +#endif + +#if do_3 +ff(3, signed char) +#endif diff --git a/gcc/testsuite/gcc.target/cris/pr93372-4.c b/gcc/testsuite/gcc.target/cris/pr93372-4.c new file mode 100644 index 000000000..e9faf9ff8 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-4.c @@ -0,0 +1,12 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +int f(int a, int *b) +{ + /* As seen in powisf2, the result of a shift is checked for zeroness. */ + int c = a >> 1; + *b = (c == 0); + return c; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-6.c b/gcc/testsuite/gcc.target/cris/pr93372-6.c new file mode 100644 index 000000000..69ae55ccb --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-6.c @@ -0,0 +1,18 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ +/* { dg-final { scan-assembler "\tlsr|\tsmi" } } */ + +/* Regarding the "lsr", see pr93372-2.c; we get a shift for the + sign-bit. For "<", that's equally optimal to smi; we just want this + test to be different with the "<" instead of ">=". */ + +int f(int a, int b, int *d) +{ + int c = a + b; + + *d = (c == 0); + + return c < 0; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-7.c b/gcc/testsuite/gcc.target/cris/pr93372-7.c new file mode 100644 index 000000000..fb22b20d9 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-7.c @@ -0,0 +1,85 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */ + +#ifndef t +#define t int +#endif + +t feq(t *a, t *b) +{ + t c = *a; + *b = c == 0; + return c; +} + +t fne(t *a, t *b) +{ + t c = *a; + *b = c != 0; + return c; +} + +t fgt(t *a, t *b) +{ + t c = *a; + *b = c > 0; + return c; +} + +unsigned t fgtu(unsigned t *a, unsigned t *b) +{ + unsigned t c = *a; + *b = c > 0; + return c; +} + +t flt(t *a, t *b) +{ + t c = *a; + *b = c < 0; + return c; +} + +#if 0 +/* Always false... */ +unsigned t fltu(unsigned t *a, unsigned t *b) +{ + unsigned t c = *a; + *b = c < 0; + return c; +} +#endif + +t fge(t *a, t *b) +{ + t c = *a; + *b = c >= 0; + return c; +} + +#if 0 +/* Always true... */ +unsigned t fgeu(unsigned t *a, unsigned t *b) +{ + unsigned t c = *a; + *b = c > 0; + return c; +} +#endif + +t fle(t *a, t *b) +{ + t c = *a; + *b = c <= 0; + return c; +} + +/* Same as eq... */ +unsigned t fleu(unsigned t *a, unsigned t *b) +{ + unsigned t c = *a; + *b = c <= 0; + return c; +} diff --git a/gcc/testsuite/gcc.target/cris/pr93372-9.c b/gcc/testsuite/gcc.target/cris/pr93372-9.c new file mode 100644 index 000000000..9a11b8c06 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/pr93372-9.c @@ -0,0 +1,9 @@ +/* Check that eliminable compare-instructions are eliminated. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "\tcmp" 1 } } */ +/* { dg-final { scan-assembler-not "\ttest" } } */ + +#define t short int +#include "pr93372-3.c" +#include "pr93372-7.c"