From patchwork Tue Dec 13 09:27:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 32722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp10720wrn; Tue, 13 Dec 2022 01:28:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf50FoRNV8BqiyMvGavkm2eeK6pGHwTU5STGLdAfjAgFFISor7NzQ3aH7cpayLE+r4wLfLIc X-Received: by 2002:a17:906:ca51:b0:7c0:d23c:ead3 with SMTP id jx17-20020a170906ca5100b007c0d23cead3mr4059147ejb.27.1670923695097; Tue, 13 Dec 2022 01:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670923695; cv=none; d=google.com; s=arc-20160816; b=M5AhBjR5F3nHbsMq6vUnimenfBGOdmu74XbrKhIzyvT47dYUxMpqtI9ByXnSCNnArH YN9ih5xZ1qakDe3xxyEZZxxeV9VjRSdsfCXPn545u32u806+/8rOiYRJnGLozdK0lVY8 OXZofZhq3BUeuAA2n9wP2G2fxiqhgAfqJg9DhP4stVlMG2SL9SQ1RzTiIymEK2fjn7TX i0/0p3fg3i2tH7Ymtt5r0HXld3Ki4ND0D67zZP8oqTiFgqiEbYGROnzcUzd6fUOjuIUI FmRWpPFFbVbx+bSc/5825qIWQTd+A5y5ZyklbQw/2QIdyld30bCSWKV1GePx+pKINPvJ pzqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=B+Rd9wLSTV4w7vNDgXEULUWsg/58GYX60M5b/++aKNw=; b=eiDt1wVU74CeVFKaVwqI+pnRWwfXbkdV6MUeuVjjIIDFzjyZICcW3okeBl//hky5S6 tA5CtfelPb+aB10h5PmW0UljH/6IeXcNIMIoOlmfsj4wMjlT6x7miNhpl3rkz/NQwv5R GjMTbTRGh4C4c22oS+QsQeONFsn2LiTCGbcE+RA8ua+hiepr8HEs83oW+QiJpj3ipJVY 2OHsE7mHhI1FXCiHIF4QsS0axDn1AWBxkGGTM/jZ2T5ePC0fn5fDFqrcsD+is0PisB1/ Bd6FL1hV7JNtQjc8a8ZW7ODeRKsugzl/ulL7BO5R7ZVMrk7CxdNUpBXYku+IpbA01kR6 WwZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gZk6i9Qa; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d23-20020a50fb17000000b0046aeca41c55si8947027edq.212.2022.12.13.01.28.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 01:28:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gZk6i9Qa; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1AD29387220C for ; Tue, 13 Dec 2022 09:28:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AD29387220C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670923694; bh=B+Rd9wLSTV4w7vNDgXEULUWsg/58GYX60M5b/++aKNw=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gZk6i9QaptRkmqfLb2njLz/PZA0N2qCLDXsjh1lPtR0vAdSC19AZZZ5e3okegXti4 w+yMHYBYjn/tIwMWBm4YzJO2zF7JKId12BCMwmr0NXYb10QUakAufrTVLnCxxdmi51 Vhs53P0Og7RoGGaY8S8d27gqzXfyiWnXEDZBRENY= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 2B9573872209 for ; Tue, 13 Dec 2022 09:27:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2B9573872209 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-135-rYna62gGPPaVPg8vABFZCg-1; Tue, 13 Dec 2022 04:27:26 -0500 X-MC-Unique: rYna62gGPPaVPg8vABFZCg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2B4A1C07565; Tue, 13 Dec 2022 09:27:25 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E3E4112131B; Tue, 13 Dec 2022 09:27:25 +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 2BD9RKGQ1938996 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 13 Dec 2022 10:27:21 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BD9RKPk1938995; Tue, 13 Dec 2022 10:27:20 +0100 Date: Tue, 13 Dec 2022 10:27:19 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] vect-patterns: Fix up vect_recog_rotate_pattern [PR108064] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752090484354118409?= X-GMAIL-MSGID: =?utf-8?q?1752090484354118409?= Hi! Since vect_recog_rotate_pattern has been extended to work also on signed types in r13-1100 we miscompile the testcase below. vect_recog_rotate_pattern actually emits correct scalar code into the pattern def sequence (in particular cast to utype, doing the 2 shifts in utype so that the right shift is logical and not arithmetic, or and then cast back to the signed type), but it didn't supply vectype for most of those pattern statements, which means that the generic handling fills it up later with the vectype provided by vect_recog_rotate_pattern. The problem is that it is vectype of the result of the whole pattern, i.e. vector of signed values in this case, while the conversion to utype, 2 shifts and or (everything with utype lhs in scalar code) should have uvectype as STMT_VINFO_VECTYPE. Fixed with following patch, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-12-13 Jakub Jelinek PR tree-optimization/108064 * tree-vect-patterns.cc (vect_recog_rotate_pattern): Pass uvectype as 4th argument to append_pattern_def_seq for statements with lhs with utype type. * gcc.c-torture/execute/pr108064.c: New test. Jakub --- gcc/tree-vect-patterns.cc.jj 2022-12-05 11:10:37.000000000 +0100 +++ gcc/tree-vect-patterns.cc 2022-12-12 13:14:23.356628767 +0100 @@ -3113,7 +3113,7 @@ vect_recog_rotate_pattern (vec_info *vin { def = vect_recog_temp_ssa_var (utype, NULL); def_stmt = gimple_build_assign (def, NOP_EXPR, oprnd0); - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); oprnd0 = def; } @@ -3137,7 +3137,7 @@ vect_recog_rotate_pattern (vec_info *vin { def = vect_recog_temp_ssa_var (utype, NULL); def_stmt = gimple_build_assign (def, NOP_EXPR, oprnd1); - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); } stype = TREE_TYPE (def); @@ -3185,13 +3185,13 @@ vect_recog_rotate_pattern (vec_info *vin def_stmt = gimple_build_assign (var1, rhs_code == LROTATE_EXPR ? LSHIFT_EXPR : RSHIFT_EXPR, oprnd0, def); - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); var2 = vect_recog_temp_ssa_var (utype, NULL); def_stmt = gimple_build_assign (var2, rhs_code == LROTATE_EXPR ? RSHIFT_EXPR : LSHIFT_EXPR, oprnd0, def2); - append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); + append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype); /* Pattern detected. */ vect_pattern_detected ("vect_recog_rotate_pattern", last_stmt); @@ -3202,7 +3202,7 @@ vect_recog_rotate_pattern (vec_info *vin if (!useless_type_conversion_p (type, utype)) { - append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt); + append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt, uvectype); tree result = vect_recog_temp_ssa_var (type, NULL); pattern_stmt = gimple_build_assign (result, NOP_EXPR, var); } --- gcc/testsuite/gcc.c-torture/execute/pr108064.c.jj 2022-12-12 13:22:29.875542508 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr108064.c 2022-12-12 13:21:32.516377957 +0100 @@ -0,0 +1,28 @@ +/* PR tree-optimization/108064 */ + +static inline short +foo (short value) +{ + return ((value >> 8) & 0xff) | ((value & 0xff) << 8); +} + +__attribute__((noipa)) +void +bar (short *d, const short *s) +{ + for (unsigned long i = 0; i < 4; i++) + d[i] = foo (s[i]); +} + +int +main () +{ + short a[4] __attribute__((aligned (16))) = { 0xff, 0, 0, 0 }; + short b[4] __attribute__((aligned (16))); + short c[4] __attribute__((aligned (16))); + + bar (b, a); + bar (c, b); + if (a[0] != c[0]) + __builtin_abort (); +}