From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102922 invoked by alias); 9 Sep 2016 00:01:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 102708 invoked by uid 89); 9 Sep 2016 00:01:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 spammy=mtune, UD:combine.c, const_int_p, intval X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Sep 2016 00:01:24 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bi9Fw-0001rx-Ro for gcc-patches@gcc.gnu.org; Thu, 08 Sep 2016 20:01:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55084) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bi9Fw-0001rM-KY for gcc-patches@gcc.gnu.org; Thu, 08 Sep 2016 20:01:20 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B04E06CB4B for ; Fri, 9 Sep 2016 00:01:18 +0000 (UTC) Received: from c64.redhat.com (vpn-232-118.phx2.redhat.com [10.3.232.118]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8901DiB023199; Thu, 8 Sep 2016 20:01:18 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 7/9] combine.c selftests Date: Fri, 09 Sep 2016 00:01:00 -0000 Message-Id: <1473381053-18817-8-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1473381053-18817-1-git-send-email-dmalcolm@redhat.com> References: <1473381053-18817-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg00483.txt.bz2 gcc/ChangeLog: * combine.c: Include selftest.h and selftest-rtl.h. (try_combine): Add assertion on this_basic_block. (class selftest::combine_test): New subclass of selftest::tl_dump_test. (selftest::combine_test::combine_test): New ctor. (selftest::test_combining_shifts): New function. (selftest::test_non_combinable_shifts): New function. (selftest::combine_c_tests): New function. * selftest-run-tests.c (selftest::run_tests): Run selftest::combine_c_tests. * selftest.h (selftest::combine_c_tests): New decl. --- gcc/combine.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++ gcc/selftest-run-tests.c | 1 + gcc/selftest.h | 1 + 3 files changed, 157 insertions(+) diff --git a/gcc/combine.c b/gcc/combine.c index 1b262f9..9c148bb 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -102,6 +102,8 @@ along with GCC; see the file COPYING3. If not see #include "valtrack.h" #include "rtl-iter.h" #include "print-rtl.h" +#include "selftest.h" +#include "selftest-rtl.h" #ifndef LOAD_EXTEND_OP #define LOAD_EXTEND_OP(M) UNKNOWN @@ -2625,6 +2627,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, rtx new_other_notes; int i; + gcc_assert (this_basic_block); + /* Immediately return if any of I0,I1,I2 are the same insn (I3 can never be). */ if (i1 == i2 || i0 == i2 || (i0 && i0 == i1)) @@ -14441,3 +14445,154 @@ make_pass_combine (gcc::context *ctxt) { return new pass_combine (ctxt); } + +#if CHECKING_P + +namespace selftest { + +/* A subclass of rtl_dump_test for testing combine.c. */ + +class combine_test : public rtl_dump_test +{ + public: + combine_test (const char *dump_content, int dumped_first_pseudo_regno); + + private: + dataflow_test m_df_test; +}; + +/* combine_test's constructor. Write DUMP_CONTENT to a tempfile and load + it. Initialize df and perform dataflow analysis. */ + +combine_test::combine_test (const char *dump_content, + int dumped_first_pseudo_regno) +: rtl_dump_test (dump_content, dumped_first_pseudo_regno), + m_df_test () +{ + /* The dataflow instance should have been created by m_df_test's ctor. */ + gcc_assert (df); + + /* From rest_of_handle_combine. */ + df_set_flags (/*DF_LR_RUN_DCE + */ DF_DEFER_INSN_RESCAN); + df_note_add_problem (); + df_analyze (); +} + +/* Verify that combine_instructions works, for combining a pair of shifts. + Ideally we'd test try_combine by itself, but a fair amount of + refactoring would be needed to do so. */ + +static void +test_combining_shifts () +{ + /* Taken from + gcc/testsuite/gcc.dg/asr_div1.c -O2 -fdump-rtl-all -mtune=cortex-a53 + for aarch64, hand editing the prev/next insns to 0 as needed, and + editing whitespace to avoid over-long lines. */ + const char *input_dump + = ("(insn 8 0 9 2 (set (reg:DI 78)\n" + " (lshiftrt:DI (reg:DI 76)\n" + " (const_int 32 [0x20])))\n" + " ../../src/gcc/testsuite/gcc.dg/asr_div1.c:14\n" + " 641 {*aarch64_lshr_sisd_or_int_di3}\n" + " (expr_list:REG_DEAD (reg:DI 76)\n" + " (nil)))\n" + "(insn 9 8 0 2 (set (reg:SI 79)\n" + " (ashiftrt:SI (subreg:SI (reg:DI 78) 0)\n" + " (const_int 3 [0x3])))\n" + " ../../src/gcc/testsuite/gcc.dg/asr_div1.c:14\n" + " 642 {*aarch64_ashr_sisd_or_int_si3}\n" + " (expr_list:REG_DEAD (reg:DI 78)\n" + " (nil)))\n"); + combine_test t (input_dump, 76); + + rtx_insn *insn_8 = get_insn_by_uid (8); + ASSERT_TRUE (insn_8); + + rtx_insn *insn_9 = get_insn_by_uid (9); + ASSERT_TRUE (insn_9); + + int rebuild_jump_labels_after_combine + = combine_instructions (get_insns (), max_reg_num ()); + ASSERT_FALSE (rebuild_jump_labels_after_combine); + + /* Verify that insns 8 and 9 were combined. */ + ASSERT_EQ (1, combine_merges); + + /* insn 8 should now be deleted. */ + ASSERT_EQ (NOTE, GET_CODE (insn_8)); + ASSERT_EQ (NOTE_INSN_DELETED, NOTE_KIND (insn_8)); + + /* insn 9 should now be a shift of 35. + On aarch64 it's a set; on x86_64 it's a parallel of a set and a clobber + of CC. */ + rtx set_in_9 = single_set (insn_9); + ASSERT_TRUE (set_in_9); + rtx src_of_9 = SET_SRC (set_in_9); + ASSERT_EQ (ASHIFTRT, GET_CODE (src_of_9)); + rtx amt = XEXP (src_of_9, 1); + ASSERT_TRUE (CONST_INT_P (amt)); + ASSERT_EQ (35, INTVAL (amt)); +} + +/* Test of failing to combine instructions. + + Similar to test_combining_shifts, but with the input register + for the 2nd shift hand-edited (from 78 to 80) so that it doesn't come + from the output of the 1st shift, so that the shifts should *not* + be combinable. */ + +static void +test_non_combinable_shifts () +{ + const char *input_dump + = ("(insn 8 0 9 2 (set (reg:DI 78)\n" + " (lshiftrt:DI (reg:DI 76)\n" + " (const_int 32 [0x20])))\n" + " ../../src/gcc/testsuite/gcc.dg/asr_div1.c:14\n" + " 641 {*aarch64_lshr_sisd_or_int_di3}\n" + " (expr_list:REG_DEAD (reg:DI 76)\n" + " (nil)))\n" + "(insn 9 8 0 2 (set (reg:SI 79)\n" + " (ashiftrt:SI (subreg:SI (reg:DI 80) 0)\n" + " (const_int 3 [0x3])))\n" + " ../../src/gcc/testsuite/gcc.dg/asr_div1.c:14\n" + " 642 {*aarch64_ashr_sisd_or_int_si3}\n" + " (expr_list:REG_DEAD (reg:DI 78)\n" + " (nil)))\n"); + combine_test t (input_dump, 76); + + rtx_insn *insn_8 = get_insn_by_uid (8); + ASSERT_TRUE (insn_8); + + rtx_insn *insn_9 = get_insn_by_uid (9); + ASSERT_TRUE (insn_9); + + int rebuild_jump_labels_after_combine + = combine_instructions (get_insns (), max_reg_num ()); + ASSERT_FALSE (rebuild_jump_labels_after_combine); + + /* Verify that no insns were combined. */ + ASSERT_EQ (0, combine_merges); + + /* insn 8 should not have be touched. */ + ASSERT_EQ (INSN, GET_CODE (insn_8)); +} + +/* Run all of the selftests within this file. */ + +void +combine_c_tests () +{ + /* Only run these tests for i386. */ +#ifndef I386_OPTS_H + return; +#endif + + test_combining_shifts (); + test_non_combinable_shifts (); +} + +} // namespace selftest + +#endif /* #if CHECKING_P */ diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c index 14e5828..296fe00 100644 --- a/gcc/selftest-run-tests.c +++ b/gcc/selftest-run-tests.c @@ -68,6 +68,7 @@ selftest::run_tests () /* Higher-level tests, or for components that other selftests don't rely on. */ + combine_c_tests (); diagnostic_show_locus_c_tests (); diagnostic_c_tests (); edit_context_c_tests (); diff --git a/gcc/selftest.h b/gcc/selftest.h index 037a5ee..8b94c3a 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -190,6 +190,7 @@ extern void forcibly_ggc_collect (); /* Declarations for specific families of tests (by source file), in alphabetical order. */ extern void bitmap_c_tests (); +extern void combine_c_tests (); extern void df_core_c_tests (); extern void diagnostic_c_tests (); extern void diagnostic_show_locus_c_tests (); -- 1.8.5.3