From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by sourceware.org (Postfix) with ESMTPS id 2CCF43938D15 for ; Thu, 8 Dec 2022 10:52:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CCF43938D15 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-xb2b.google.com with SMTP id v71so1161420ybv.6 for ; Thu, 08 Dec 2022 02:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=AcrRSWZMytm+zccNJvh0iPZNMdVV068u2yBCBHIHvcM=; b=EfJD+Zc8zMCPRtZBH0FqsbAodx/sppY2LSVbBFvNMQSyQZ6WIUUmdXmbtd3UOJxfZk r1ubPpSagr6oZl0PEMKlXpwLlDDbnJNHGoXH/1C3DXGcqaJkkpUhhXkxcvTDHwP2gOzx nzMRXg+dMzx0VU16OauUQ6aDpcnp4w/viDEaLSyLnF2pgNuMXzfjpYYPpxPhEZYlUpaI fMQFkUJsOj0qwBpbbFTwkY0E2RRHET6K4GSbK0hGm1fzopu4I0dJo/fbH27Q+jw1id+a SmKBB0HQeuEOjrbcB5SqifFsAPqUt2x0FCqxvF532azPiA/hWCUEmDvnPKEn+4VZRFbX /WpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AcrRSWZMytm+zccNJvh0iPZNMdVV068u2yBCBHIHvcM=; b=2+tvjrA6C+mON8RoWyxhmeIgG/W94vbNRc7KGX0x7W9xudKAfy+0fc8uie9hie8rr8 teogMayBVebspKVoeMroBl+uAWm2dchyvR48DSMyAEUwuXp9QDmq/nE6Zv0BdbYlF4vV ZP8VJNfw2VprqKDkQ7XeHU0Nw4+PR3cONmNgEdAJIIYz1NtKdJlV8MT6igewVIHJlcUz hwi953xvzMz3fwptLfc1cbUDolP08jzmGcl7f6yb+S7StGsruahnKzPPO3UQ+qjsyFsG PMOuVRCXx1HGdc/5PkbsCiDbrL2h8YF7+w88XAD/PUnsf7Tx67wpY926nylZ0KV5oLBl wO6g== X-Gm-Message-State: ANoB5pmKfNcF9Y+5zNEVCAQkHa/BZ27b4WFHyC42u19MHXC3QJav9Ljz aIml8BHKNZp60PERVbEN2RzVbnVFqDuR0dWncmA= X-Google-Smtp-Source: AA0mqf5x6qTYQP7w1qNbAETdMPofKVKaq+knjdLJ1+c5KZPeYrQOLlvIffo1Hp8y2EhyHa8z3wnR0KO4kY6Zv5SyF7o= X-Received: by 2002:a25:b1a5:0:b0:6f4:c7dd:1e0a with SMTP id h37-20020a25b1a5000000b006f4c7dd1e0amr48306295ybj.223.1670496722448; Thu, 08 Dec 2022 02:52:02 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Uros Bizjak Date: Thu, 8 Dec 2022 11:51:51 +0100 Message-ID: Subject: Re: [PATCH] i386: Add *concat3_{5,6,7} patterns [PR107627] To: Jakub Jelinek Cc: Roger Sayle , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Dec 8, 2022 at 10:49 AM Jakub Jelinek wrote: > > Hi! > > On Thu, Dec 01, 2022 at 09:09:51AM +0100, Jakub Jelinek via Gcc-patches wrote: > > BTW, I wonder if we couldn't add additional patterns which would catch > > the case where one of the operands is constant. > > The following patch does add those. > The difference with the patch on the 2 testcases is: > baz: > - movq 8(%rsi), %rax > + movq 8(%rsi), %rsi > + movq %rdi, %r8 > movl %edx, %ecx > - xorl %r8d, %r8d > - xorl %edx, %edx > - movabsq $-2401053089206453570, %r9 > - orq %r8, %rax > - orq %r9, %rdx > - shrdq %rdx, %rax > - movq %rax, (%rdi) > + movabsq $-2401053089206453570, %rdi > + movq %rsi, %rax > + shrdq %rdi, %rax > + movq %rax, (%r8) > qux: > - movq (%rsi), %rax > + movq %rdi, %r8 > + movq (%rsi), %rdi > movl %edx, %ecx > - xorl %r9d, %r9d > - movabsq $-2401053089206453570, %r8 > - movq %rax, %rdx > - xorl %eax, %eax > - orq %r8, %rax > - orq %r9, %rdx > - shrdq %rdx, %rax > - movq %rax, (%rdi) > + movabsq $-2401053089206453570, %rsi > + movq %rsi, %rax > + shrdq %rdi, %rax > + movq %rax, (%r8) > and > garply: > pushl %esi > - xorl %edx, %edx > + movl $-559038737, %esi > pushl %ebx > movl 16(%esp), %eax > - orl $-559038737, %edx > movl 20(%esp), %ecx > - movl 4(%eax), %eax > - shrdl %edx, %eax > movl 12(%esp), %edx > + movl 4(%eax), %ebx > + movl %ebx, %eax > + shrdl %esi, %eax > fred: > ... > movl 16(%esp), %eax > + movl $-889275714, %ebx > movl 20(%esp), %ecx > - movl (%eax), %eax > - movl %eax, %edx > - movl $0, %eax > - orl $-889275714, %eax > - shrdl %edx, %eax > movl 12(%esp), %edx > + movl (%eax), %esi > + movl %ebx, %eax > + shrdl %esi, %eax > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2022-12-08 Jakub Jelinek > > PR target/107627 > * config/i386/i386.md (HALF, half): New mode attributes. > (*concat3_5, *concat3_6, > *concat3_7): New define_insn_and_split patterns. > > * gcc.target/i386/pr107627-3.c: New test. > * gcc.target/i386/pr107627-4.c: New test. LGTM. Thanks, Uros. > --- gcc/config/i386/i386.md.jj 2022-12-06 12:16:31.059905487 +0100 > +++ gcc/config/i386/i386.md 2022-12-07 15:11:55.297914206 +0100 > @@ -1134,6 +1134,10 @@ (define_mode_attr MODE_SIZE [(QI "1") (H > (define_mode_attr DWI [(QI "HI") (HI "SI") (SI "DI") (DI "TI") (TI "OI")]) > (define_mode_attr dwi [(QI "hi") (HI "si") (SI "di") (DI "ti") (TI "oi")]) > > +;; Half sized integer modes. > +(define_mode_attr HALF [(TI "DI") (DI "SI")]) > +(define_mode_attr half [(TI "di") (DI "si")]) > + > ;; LEA mode corresponding to an integer mode > (define_mode_attr LEAMODE [(QI "SI") (HI "SI") (SI "SI") (DI "DI")]) > > @@ -11464,6 +11468,80 @@ (define_insn_and_split "*concat split_double_concat (mode, operands[0], operands[1], operands[2]); > DONE; > }) > + > +(define_insn_and_split "*concat3_5" > + [(set (match_operand:DWI 0 "nonimmediate_operand" "=ro") > + (any_or_plus:DWI > + (ashift:DWI (match_operand:DWI 1 "register_operand" "r") > + (match_operand:DWI 2 "const_int_operand")) > + (match_operand:DWI 3 "const_scalar_int_operand")))] > + "INTVAL (operands[2]) == * BITS_PER_UNIT / 2 > + && (mode == DImode > + ? CONST_INT_P (operands[3]) > + && (UINTVAL (operands[3]) & ~GET_MODE_MASK (SImode)) == 0 > + : CONST_INT_P (operands[3]) > + ? INTVAL (operands[3]) >= 0 > + : CONST_WIDE_INT_NUNITS (operands[3]) == 2 > + && CONST_WIDE_INT_ELT (operands[3], 1) == 0)" > + "#" > + "&& reload_completed" > + [(clobber (const_int 0))] > +{ > + rtx op3 = simplify_subreg (mode, operands[3], mode, 0); > + split_double_concat (mode, operands[0], op3, > + gen_lowpart (mode, operands[1])); > + DONE; > +}) > + > +(define_insn_and_split "*concat3_6" > + [(set (match_operand: 0 "nonimmediate_operand" "=ro,r") > + (any_or_plus: > + (ashift: > + (zero_extend: > + (match_operand:DWIH 1 "nonimmediate_operand" "r,m")) > + (match_operand: 2 "const_int_operand")) > + (match_operand: 3 "const_scalar_int_operand")))] > + "INTVAL (operands[2]) == * BITS_PER_UNIT > + && (mode == DImode > + ? CONST_INT_P (operands[3]) > + && (UINTVAL (operands[3]) & ~GET_MODE_MASK (SImode)) == 0 > + : CONST_INT_P (operands[3]) > + ? INTVAL (operands[3]) >= 0 > + : CONST_WIDE_INT_NUNITS (operands[3]) == 2 > + && CONST_WIDE_INT_ELT (operands[3], 1) == 0)" > + "#" > + "&& reload_completed" > + [(clobber (const_int 0))] > +{ > + rtx op3 = simplify_subreg (mode, operands[3], mode, 0); > + split_double_concat (mode, operands[0], op3, operands[1]); > + DONE; > +}) > + > +(define_insn_and_split "*concat3_7" > + [(set (match_operand: 0 "nonimmediate_operand" "=ro,r") > + (any_or_plus: > + (zero_extend: > + (match_operand:DWIH 1 "nonimmediate_operand" "r,m")) > + (match_operand: 2 "const_scalar_int_operand")))] > + "mode == DImode > + ? CONST_INT_P (operands[2]) > + && (UINTVAL (operands[2]) & GET_MODE_MASK (SImode)) == 0 > + : CONST_WIDE_INT_P (operands[2]) > + && CONST_WIDE_INT_NUNITS (operands[2]) == 2 > + && CONST_WIDE_INT_ELT (operands[2], 0) == 0" > + "#" > + "&& reload_completed" > + [(clobber (const_int 0))] > +{ > + rtx op2; > + if (mode == DImode) > + op2 = gen_int_mode (INTVAL (operands[2]) >> 32, mode); > + else > + op2 = gen_int_mode (CONST_WIDE_INT_ELT (operands[2], 1), mode); > + split_double_concat (mode, operands[0], operands[1], op2); > + DONE; > +}) > > ;; Negation instructions > > --- gcc/testsuite/gcc.target/i386/pr107627-3.c.jj 2022-12-07 15:27:56.214095258 +0100 > +++ gcc/testsuite/gcc.target/i386/pr107627-3.c 2022-12-07 13:22:44.728247774 +0100 > @@ -0,0 +1,28 @@ > +/* PR target/107627 */ > +/* { dg-do compile { target int128 } } */ > +/* { dg-options "-O2 -masm=att" } */ > +/* { dg-final { scan-assembler-not "\torq\t" } } */ > + > +static inline unsigned __int128 > +foo (unsigned long long x, unsigned long long y) > +{ > + return ((unsigned __int128) x << 64) | y; > +} > + > +static inline unsigned long long > +bar (unsigned long long x, unsigned long long y, unsigned z) > +{ > + return foo (x, y) >> (z % 64); > +} > + > +void > +baz (unsigned long long *x, const unsigned long long *y, unsigned z) > +{ > + x[0] = bar (0xdeadbeefcafebabeULL, y[1], z); > +} > + > +void > +qux (unsigned long long *x, const unsigned long long *y, unsigned z) > +{ > + x[0] = bar (y[0], 0xdeadbeefcafebabeULL, z); > +} > --- gcc/testsuite/gcc.target/i386/pr107627-4.c.jj 2022-12-07 15:27:59.519047759 +0100 > +++ gcc/testsuite/gcc.target/i386/pr107627-4.c 2022-12-07 13:23:28.050621778 +0100 > @@ -0,0 +1,28 @@ > +/* PR target/107627 */ > +/* { dg-do compile { target ia32 } } */ > +/* { dg-options "-O2 -masm=att" } */ > +/* { dg-final { scan-assembler-not "\torl\t" } } */ > + > +static inline unsigned long long > +qux (unsigned int x, unsigned int y) > +{ > + return ((unsigned long long) x << 32) | y; > +} > + > +static inline unsigned int > +corge (unsigned int x, unsigned int y, unsigned z) > +{ > + return qux (x, y) >> (z % 32); > +} > + > +void > +garply (unsigned int *x, const unsigned int *y, unsigned z) > +{ > + x[0] = corge (0xdeadbeefU, y[1], z); > +} > + > +void > +fred (unsigned int *x, const unsigned int *y, unsigned z) > +{ > + x[0] = corge (y[0], 0xcafebabeU, z); > +} > > > Jakub >