From patchwork Fri Jul 9 09:49:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1502988 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tZGUlIQr; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLpKz1NMlz9sWX for ; Fri, 9 Jul 2021 19:49:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F31063984064 for ; Fri, 9 Jul 2021 09:49:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F31063984064 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1625824197; bh=ZSNTB78w5T0a+g0tM1gJuSR8DVROR/TGpWG3gaP1oQI=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tZGUlIQrRMUx6CS0ewrtDkaU7M/AIxrFNYeZCWi+H4FU+xTKDllo977cTzeG2rz65 0EkU9VS13HjfS7d6mdO0Q80MBvOeBDfwjpjFwj9unPqJI6Q9Lile4KZopf9b+4LlEH mLCpUm1x51WFUxWAjALzoL4nkKmElAeXJV2FO54Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by sourceware.org (Postfix) with ESMTPS id CAEC638515FE for ; Fri, 9 Jul 2021 09:49:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CAEC638515FE Received: by mail-qt1-x82b.google.com with SMTP id g8so7161036qth.10 for ; Fri, 09 Jul 2021 02:49:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ZSNTB78w5T0a+g0tM1gJuSR8DVROR/TGpWG3gaP1oQI=; b=Hat36aGJ7+N5JnTy4td/0XZApy3e03YB9qNM9Qdb9EEHRnhGI0/W/5EJetcIr9qDvY 7AJ6x8qkWaTvPIRy+9OLJqEueVZiLHj2s1My7YIzXoEbDvNXjjRbONc0xXXAWtDvTIzH 0POWGRNtFP+084TBhYBEi7Z7QeWCfafpeiMDPISmaTYOl7zJ9MZo+dQGlg2GVuyrb4M9 sa1v9La+Lj+U6lr6EFLXBHK/SWbfzLlXY/CdQst358yZX5PdR4LKPti9DRAZVYrI5vNl yyNaSZJjDPb3BjVILpBJsKZIEBANR2eXj8sGM3W/AXy8P/yMqkWGch001VBO4mln8GWx yRDA== X-Gm-Message-State: AOAM533XPlAdXTKePIaS0nbqYjn9y1M0SpXGnEJ2aI2uJHboPKDj3+0D 1xRrXN6S8aspV/Fve/sR4BNlFjfqXTBvXBR7hnPywgalLYXdig== X-Google-Smtp-Source: ABdhPJzTYHdWRaNlwCtZAI/LgWGv7xe1ZFbGRX87iUk2p1OUh86PkOD8LWqTln5n+xHDnWREODk/fK0TTaJDiUQYuuY= X-Received: by 2002:ac8:7f53:: with SMTP id g19mr30375969qtk.225.1625824175204; Fri, 09 Jul 2021 02:49:35 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 9 Jul 2021 11:49:23 +0200 Message-ID: Subject: [PATCH] i386: Fix *udivmodsi4_pow2_zext_? patterns To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Uros Bizjak via Gcc-patches From: Uros Bizjak Reply-To: Uros Bizjak Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In addition to the obvious cut-n-pasto where *udivmodsi4_pow2_zext_2 never matches, limit the range of the immediate operand to prevent out of range immediate operand of AND instruction. Found by inspection, the patterns rarely match (if at all), since tree optimizers do the transformation before RTL is generated. But according to the comment above *udivmod4_pow2, the constant can materialize after expansion, so leave these patterns around for now. 2021-07-09 Uroš Bizjak gcc/ * config/i386/i386.md (*udivmodsi4_pow2_zext_1): Limit the log2 range of operands[3] to [1,31]. (*udivmodsi4_pow2_zext_2): Ditto. Correct insn RTX pattern. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Pushed to master. Uros. diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 156c6a94989..26fb81b9b4b 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -8518,7 +8518,7 @@ (define_insn_and_split "*udivmodsi4_pow2_zext_1" (umod:SI (match_dup 2) (match_dup 3))) (clobber (reg:CC FLAGS_REG))] "TARGET_64BIT - && exact_log2 (UINTVAL (operands[3])) > 0" + && IN_RANGE (exact_log2 (UINTVAL (operands[3])), 1, 31)" "#" "&& reload_completed" [(set (match_dup 1) (match_dup 2)) @@ -8599,10 +8599,10 @@ (define_insn_and_split "*udivmodsi4_pow2_zext_2" (umod:SI (match_operand:SI 2 "register_operand" "0") (match_operand:SI 3 "const_int_operand" "n")))) (set (match_operand:SI 0 "register_operand" "=r") - (umod:SI (match_dup 2) (match_dup 3))) + (udiv:SI (match_dup 2) (match_dup 3))) (clobber (reg:CC FLAGS_REG))] "TARGET_64BIT - && exact_log2 (UINTVAL (operands[3])) > 0" + && IN_RANGE (exact_log2 (UINTVAL (operands[3])), 1, 31)" "#" "&& reload_completed" [(set (match_dup 1) (match_dup 2))