From patchwork Tue Dec 13 09:20:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61859 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1CF363864A21 for ; Tue, 13 Dec 2022 09:21:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CF363864A21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670923274; bh=usfpC2va3mw95o5oByaGypqoWrLM0kzt9y2cMCTfOHQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=v99Tx7KQayGCUY4rV32VAnK3feaVuXIXh+hNoMVXXG0T4Lr4W7ZP15qJuclaCZ0N1 xm6g6NcfdeWPsSEKDiSDquym1r7oGxOkUam8pqzjCT93UFZHKtAdwqPZyAV6iORpbV Msj8zbyl4BNlcpKirCI+X6Wbp0RGeKkMlNaYzHLU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4F426384C91A for ; Tue, 13 Dec 2022 09:20:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F426384C91A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-asys6YciM5W4Bfd6TSZFcQ-1; Tue, 13 Dec 2022 04:20:40 -0500 X-MC-Unique: asys6YciM5W4Bfd6TSZFcQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6AC77185A794; Tue, 13 Dec 2022 09:20:40 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25ACA4039F65; Tue, 13 Dec 2022 09:20:40 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BD9KZqa1938969 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 13 Dec 2022 10:20:35 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BD9KY2p1938968; Tue, 13 Dec 2022 10:20:34 +0100 Date: Tue, 13 Dec 2022 10:20:34 +0100 To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Fix up *concat*_{5,6,7} patterns [PR108044] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-15.0 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following patch fixes 2 issues with the *concat3_5 and *concat3_{6,7} patterns. One is that if the destination is memory rather than register, then we can't use movabsq and so can't support all the possible immediates. I see 3 possibilities to fix that. One would be to use x86_64_hilo_int_operand predicate instead of const_scalar_int_operand and thus not match it at all during combine in such cases, but that unnecessarily pessimizes also the case when it is loaded into register where we can use movabsq. Another one is what is implemented in the patch, use Wd constraint for the integer on 64-bit if destination is memory and X (didn't find more appropriate one which would accept any const_int/const_wide_int and the value checking is done in the conditions) otherwise. Yet another option would be to add match_scratch to the pattern and use it with =X constraints except for the =o case for 64-bit non-Wd where it would give a single DImode register (rather than 2). Another thing is that if one half of the constant is ix86_endbr_immediate_operand, then for -fcf-protection=branch we force those constants into memory and that might not work properly with -fpic. So we should refuse to match with such constants. OT, seems for movabsq we don't check that and happily allow the endbr pattern in the immediate. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk, or do you prefer another way to do it (see above)? 2022-12-13 Jakub Jelinek PR target/108044 * config/i386/i386.md (*concat3_5, *concat3_6, *concat3_7): Split alternative with =ro output constraint into =r,o,o and use Wd input constraint for the last alternative which is enabled for TARGET_64BIT. Reject ix86_endbr_immediate_operand in the input constant. * gcc.target/i386/pr108044-1.c: New test. * gcc.target/i386/pr108044-2.c: New test. * gcc.target/i386/pr108044-3.c: New test. * gcc.target/i386/pr108044-4.c: New test. Jakub --- gcc/config/i386/i386.md.jj 2022-12-08 14:55:38.807303856 +0100 +++ gcc/config/i386/i386.md 2022-12-12 10:37:09.332995296 +0100 @@ -11470,11 +11470,11 @@ (define_insn_and_split "*concat3_5" - [(set (match_operand:DWI 0 "nonimmediate_operand" "=ro") + [(set (match_operand:DWI 0 "nonimmediate_operand" "=r,o,o") (any_or_plus:DWI - (ashift:DWI (match_operand:DWI 1 "register_operand" "r") + (ashift:DWI (match_operand:DWI 1 "register_operand" "r,r,r") (match_operand:DWI 2 "const_int_operand")) - (match_operand:DWI 3 "const_scalar_int_operand")))] + (match_operand:DWI 3 "const_scalar_int_operand" "X,X,Wd")))] "INTVAL (operands[2]) == * BITS_PER_UNIT / 2 && (mode == DImode ? CONST_INT_P (operands[3]) @@ -11482,7 +11482,12 @@ (define_insn_and_split "*concat= 0 : CONST_WIDE_INT_NUNITS (operands[3]) == 2 - && CONST_WIDE_INT_ELT (operands[3], 1) == 0)" + && CONST_WIDE_INT_ELT (operands[3], 1) == 0) + && !(CONST_INT_P (operands[3]) + ? ix86_endbr_immediate_operand (operands[3], VOIDmode) + : ix86_endbr_immediate_operand (GEN_INT (CONST_WIDE_INT_ELT (operands[3], + 0)), + VOIDmode))" "#" "&& reload_completed" [(clobber (const_int 0))] @@ -11491,16 +11496,17 @@ (define_insn_and_split "*concatmode, operands[0], op3, gen_lowpart (mode, operands[1])); DONE; -}) +} + [(set_attr "isa" "*,nox64,x64")]) (define_insn_and_split "*concat3_6" - [(set (match_operand: 0 "nonimmediate_operand" "=ro,r") + [(set (match_operand: 0 "nonimmediate_operand" "=r,o,o,r") (any_or_plus: (ashift: (zero_extend: - (match_operand:DWIH 1 "nonimmediate_operand" "r,m")) + (match_operand:DWIH 1 "nonimmediate_operand" "r,r,r,m")) (match_operand: 2 "const_int_operand")) - (match_operand: 3 "const_scalar_int_operand")))] + (match_operand: 3 "const_scalar_int_operand" "X,X,Wd,X")))] "INTVAL (operands[2]) == * BITS_PER_UNIT && (mode == DImode ? CONST_INT_P (operands[3]) @@ -11508,7 +11514,12 @@ (define_insn_and_split "*concat= 0 : CONST_WIDE_INT_NUNITS (operands[3]) == 2 - && CONST_WIDE_INT_ELT (operands[3], 1) == 0)" + && CONST_WIDE_INT_ELT (operands[3], 1) == 0) + && !(CONST_INT_P (operands[3]) + ? ix86_endbr_immediate_operand (operands[3], VOIDmode) + : ix86_endbr_immediate_operand (GEN_INT (CONST_WIDE_INT_ELT (operands[3], + 0)), + VOIDmode))" "#" "&& reload_completed" [(clobber (const_int 0))] @@ -11516,20 +11527,25 @@ (define_insn_and_split "*concatmode, operands[3], mode, 0); split_double_concat (mode, operands[0], op3, operands[1]); DONE; -}) +} + [(set_attr "isa" "*,nox64,x64,*")]) (define_insn_and_split "*concat3_7" - [(set (match_operand: 0 "nonimmediate_operand" "=ro,r") + [(set (match_operand: 0 "nonimmediate_operand" "=r,o,o,r") (any_or_plus: (zero_extend: - (match_operand:DWIH 1 "nonimmediate_operand" "r,m")) - (match_operand: 2 "const_scalar_int_operand")))] + (match_operand:DWIH 1 "nonimmediate_operand" "r,r,r,m")) + (match_operand: 2 "const_scalar_int_operand" "X,X,Wd,X")))] "mode == DImode ? CONST_INT_P (operands[2]) && (UINTVAL (operands[2]) & GET_MODE_MASK (SImode)) == 0 + && !ix86_endbr_immediate_operand (operands[2], VOIDmode) : CONST_WIDE_INT_P (operands[2]) && CONST_WIDE_INT_NUNITS (operands[2]) == 2 - && CONST_WIDE_INT_ELT (operands[2], 0) == 0" + && CONST_WIDE_INT_ELT (operands[2], 0) == 0 + && !ix86_endbr_immediate_operand (GEN_INT (CONST_WIDE_INT_ELT (operands[2], + 1)), + VOIDmode)" "#" "&& reload_completed" [(clobber (const_int 0))] @@ -11541,7 +11557,8 @@ (define_insn_and_split "*concatmode); split_double_concat (mode, operands[0], operands[1], op2); DONE; -}) +} + [(set_attr "isa" "*,nox64,x64,*")]) ;; Negation instructions --- gcc/testsuite/gcc.target/i386/pr108044-1.c.jj 2022-12-12 10:25:23.664131494 +0100 +++ gcc/testsuite/gcc.target/i386/pr108044-1.c 2022-12-12 10:20:02.395740622 +0100 @@ -0,0 +1,33 @@ +/* PR target/108044 */ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2" } */ + +static inline unsigned __int128 +foo (unsigned long long x, unsigned long long y) +{ + return ((unsigned __int128) x << 64) | y; +} + +void +bar (unsigned __int128 *p, unsigned long long x) +{ + p[0] = foo (x, 0xdeadbeefcafebabeULL); +} + +void +baz (unsigned __int128 *p, unsigned long long x) +{ + p[0] = foo (0xdeadbeefcafebabeULL, x); +} + +void +qux (unsigned __int128 *p, unsigned long long x) +{ + p[0] = foo (x, 0xffffffffcafebabeULL); +} + +void +corge (unsigned __int128 *p, unsigned long long x) +{ + p[0] = foo (0xffffffffcafebabeULL, x); +} --- gcc/testsuite/gcc.target/i386/pr108044-2.c.jj 2022-12-12 10:25:27.069082645 +0100 +++ gcc/testsuite/gcc.target/i386/pr108044-2.c 2022-12-12 10:19:06.545541879 +0100 @@ -0,0 +1,21 @@ +/* PR target/108044 */ +/* { dg-do compile { target ia32 } } */ +/* { dg-options "-O2" } */ + +static inline unsigned long long +foo (unsigned int x, unsigned int y) +{ + return ((unsigned long long) x << 32) | y; +} + +void +bar (unsigned long long *p, unsigned int x) +{ + p[0] = foo (x, 0xcafebabeU); +} + +void +baz (unsigned long long *p, unsigned int x) +{ + p[0] = foo (0xcafebabeU, x); +} --- gcc/testsuite/gcc.target/i386/pr108044-3.c.jj 2022-12-12 10:27:08.348629628 +0100 +++ gcc/testsuite/gcc.target/i386/pr108044-3.c 2022-12-12 10:29:19.967741328 +0100 @@ -0,0 +1,33 @@ +/* PR target/108044 */ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2 -fcf-protection=branch" } */ + +static inline unsigned __int128 +foo (unsigned long long x, unsigned long long y) +{ + return ((unsigned __int128) x << 64) | y; +} + +unsigned __int128 +bar (unsigned long long x) +{ + return foo (x, 0xfa1e0ff3ULL); +} + +unsigned __int128 +baz (unsigned long long x) +{ + return foo (0xfa1e0ff3ULL, x); +} + +unsigned __int128 +qux (unsigned long long x) +{ + return foo (x, 0xffbafa1e0ff3abdeULL); +} + +unsigned __int128 +corge (unsigned long long x) +{ + return foo (0xffbafa1e0ff3abdeULL, x); +} --- gcc/testsuite/gcc.target/i386/pr108044-4.c.jj 2022-12-12 10:37:54.419345499 +0100 +++ gcc/testsuite/gcc.target/i386/pr108044-4.c 2022-12-12 10:38:43.668635715 +0100 @@ -0,0 +1,21 @@ +/* PR target/108044 */ +/* { dg-do compile { target ia32 } } */ +/* { dg-options "-O2 -fcf-protection=branch" } */ + +static inline unsigned long long +foo (unsigned int x, unsigned int y) +{ + return ((unsigned long long) x << 32) | y; +} + +unsigned long long +bar (unsigned int x) +{ + return foo (x, 0xfa1e0ff3U); +} + +unsigned long long +baz (unsigned int x) +{ + return foo (0xfa1e0ff3U, x); +}