From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by sourceware.org (Postfix) with ESMTPS id 60045385828D for ; Wed, 8 Nov 2023 16:37:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60045385828D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 60045385828D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699461467; cv=none; b=F0TzUF7ueBdu3AM8nPJagmU6fK3hc7bhP3wJa7Ag9uQnQmApua92SshTCfrf6vGYiQv+RUlguKqdUgF9BkIus9IIig8W9dF52rnCfgMCI1W990/HLfLiVwnSIEv+FD1iaykdFndr026wb7xcH7beS3r2WpVEUfBvulC98OAwlN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699461467; c=relaxed/simple; bh=pD5tA301GSutV++aR9HxPH4NFf6M1M4MDBHBzd+YsVQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=q/PGLw4Wy8YS1cuLnsYWkafOvrjd1fc8mLSv1bC7zqkZlRMJfz9kifGkmpJ3V6TT/4bKhJNaIx215CJfBfTT9aTKl8UvOljrkDy9HCNsw5huwLHHccAFLFBgTuxv1tLcek4wb23d342wEDiag/ErYY0pb2LDigOszWDA8BTXXoc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-da3b4b7c6bdso7390108276.2 for ; Wed, 08 Nov 2023 08:37:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699461465; x=1700066265; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=oWmJJo9LLyKuJPdxN8n7jQx6FF6b0VbPQju9Lzp2t1w=; b=j9SMmcVRObxW+zrhw7dNifXt/2H7fGKYo7XR+bzJs0mdq9Cgi11OHbHp/QCRjQo8mP /cPnVT0Mv0kGeynum4zZQMWNkoEw8HsIK1VkBWrPtHKnLUOgopMntu7lPglbm/Bxo9HI i/ZOy2MmLCodzwoWrinQpgT4R40D19ugDnpxi6TrkbXjetc7FF1gtXimdoR2ZmSn2Si3 Xua2uMwdcS40ws8iBjOW4DzFe8vZUVwfnbOqABVQxCDQP2Hj4+2A4iJciyzpNiKZ1C9U KtiEKPHtw3AkJwQos79QBpqVXVv49YnR5ZWBkbSCWvXcO2UJ+fZWNZDVbemi3ftppkXJ kHPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699461465; x=1700066265; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oWmJJo9LLyKuJPdxN8n7jQx6FF6b0VbPQju9Lzp2t1w=; b=s9LyELW4sYqqW6PaYG6tLEP18wKXL++kitPCDRbWEnvkAPXYBWKizolLPSa1N4LjGp HEtSpu66VXjquTnwBXLj+3WEGqBykOHRUAeV5XK1qY+RZ6ZOeka8GTAkhps0GdD7XQG8 /YhxGio2NOG6eATpBhCoXhW5bbVv+QrUzq4x6LKFI2WxKmin3iCCdO7eqmTrBKce/8HZ Ob6aTj9htgLHf7IHM2wHuwiF6vbZ30q/XAjeTNNAvns6HAxdCejBdPNgQYcQLAcQ1aAt UarXKtA2ZF0DrCyUZqckF5utWWaoWtN9x1HJvlusAaP0vAxTQDXVJ04hPky3pUy1vwYI KRuQ== X-Gm-Message-State: AOJu0Yy4KzkG17IU3RVMCoEeO95KOFdWV2E5Po3T1+RP53/ZOJO4JArr jTXd56xYLxQD2nwG2ytkXP2eqiQweqKvTONhpoFwUg== X-Google-Smtp-Source: AGHT+IFShcMLHMJLgMH7HQIe6fPU3ACELSK8luDSVKJSxeHIvN+0EARQFPozswW7OEppivXVkv4/Nw== X-Received: by 2002:a25:4094:0:b0:d81:894b:28e4 with SMTP id n142-20020a254094000000b00d81894b28e4mr2279328yba.51.1699461464724; Wed, 08 Nov 2023 08:37:44 -0800 (PST) Received: from free.home ([2804:7f1:2080:e9c8:ff5e:88e8:a900:d7b4]) by smtp.gmail.com with ESMTPSA id k3-20020a5b0a03000000b00d9abce6acf2sm6374453ybq.59.2023.11.08.08.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 08:37:44 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3A8GbYV62216042 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 8 Nov 2023 13:37:35 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Rainer Orth , Mike Stump , Jan Hubicka , Uros Bizjak Subject: [PATCH v2] i386 PIE: accept @GOTOFF in load/store multi base address Organization: Free thinker, does not speak for AdaCore Date: Wed, 08 Nov 2023 13:37:34 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_QUOTING 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: Ping? https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598872.html Looking at the code generated for sse2-{load,store}-multi.c with PIE, I realized we could use UNSPEC_GOTOFF as a base address, and that this would enable the test to use the vector insns expected by the tests even with PIC, so I extended the base + offset logic used by the SSE2 multi-load/store peepholes to accept reg + symbolic base + offset too, so that the test generated the expected insns even with PIE. Regstrapped on x86_64-linux-gnu, also tested with gcc-13 on i686- and x86_64-. Ok to install? for gcc/ChangeLog * config/i386/i386.cc (symbolic_base_address_p, base_address_p): New, factored out from... (extract_base_offset_in_addr): ... here and extended to recognize REG+GOTOFF, as in gcc.target/i386/sse2-load-multi.c and sse2-store-multi.c with PIE enabled by default. --- gcc/config/i386/i386.cc | 89 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 14 deletions(-) diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index c2bd07fced7b1..eec9b42396e0a 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -25198,11 +25198,40 @@ ix86_reloc_rw_mask (void) } #endif -/* If MEM is in the form of [base+offset], extract the two parts - of address and set to BASE and OFFSET, otherwise return false. */ +/* Return true iff ADDR can be used as a symbolic base address. */ static bool -extract_base_offset_in_addr (rtx mem, rtx *base, rtx *offset) +symbolic_base_address_p (rtx addr) +{ + if (GET_CODE (addr) == SYMBOL_REF) + return true; + + if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_GOTOFF) + return true; + + return false; +} + +/* Return true iff ADDR can be used as a base address. */ + +static bool +base_address_p (rtx addr) +{ + if (REG_P (addr)) + return true; + + if (symbolic_base_address_p (addr)) + return true; + + return false; +} + +/* If MEM is in the form of [(base+symbase)+offset], extract the three + parts of address and set to BASE, SYMBASE and OFFSET, otherwise + return false. */ + +static bool +extract_base_offset_in_addr (rtx mem, rtx *base, rtx *symbase, rtx *offset) { rtx addr; @@ -25213,21 +25242,52 @@ extract_base_offset_in_addr (rtx mem, rtx *base, rtx *offset) if (GET_CODE (addr) == CONST) addr = XEXP (addr, 0); - if (REG_P (addr) || GET_CODE (addr) == SYMBOL_REF) + if (base_address_p (addr)) { *base = addr; + *symbase = const0_rtx; *offset = const0_rtx; return true; } if (GET_CODE (addr) == PLUS - && (REG_P (XEXP (addr, 0)) - || GET_CODE (XEXP (addr, 0)) == SYMBOL_REF) - && CONST_INT_P (XEXP (addr, 1))) + && base_address_p (XEXP (addr, 0))) { - *base = XEXP (addr, 0); - *offset = XEXP (addr, 1); - return true; + rtx addend = XEXP (addr, 1); + + if (GET_CODE (addend) == CONST) + addend = XEXP (addend, 0); + + if (CONST_INT_P (addend)) + { + *base = XEXP (addr, 0); + *symbase = const0_rtx; + *offset = addend; + return true; + } + + /* Also accept REG + symbolic ref, with or without a CONST_INT + offset. */ + if (REG_P (XEXP (addr, 0))) + { + if (symbolic_base_address_p (addend)) + { + *base = XEXP (addr, 0); + *symbase = addend; + *offset = const0_rtx; + return true; + } + + if (GET_CODE (addend) == PLUS + && symbolic_base_address_p (XEXP (addend, 0)) + && CONST_INT_P (XEXP (addend, 1))) + { + *base = XEXP (addr, 0); + *symbase = XEXP (addend, 0); + *offset = XEXP (addend, 1); + return true; + } + } } return false; @@ -25242,7 +25302,8 @@ ix86_operands_ok_for_move_multiple (rtx *operands, bool load, machine_mode mode) { HOST_WIDE_INT offval_1, offval_2, msize; - rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2, offset_1, offset_2; + rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2, + symbase_1, symbase_2, offset_1, offset_2; if (load) { @@ -25265,13 +25326,13 @@ ix86_operands_ok_for_move_multiple (rtx *operands, bool load, return false; /* Check if the addresses are in the form of [base+offset]. */ - if (!extract_base_offset_in_addr (mem_1, &base_1, &offset_1)) + if (!extract_base_offset_in_addr (mem_1, &base_1, &symbase_1, &offset_1)) return false; - if (!extract_base_offset_in_addr (mem_2, &base_2, &offset_2)) + if (!extract_base_offset_in_addr (mem_2, &base_2, &symbase_2, &offset_2)) return false; /* Check if the bases are the same. */ - if (!rtx_equal_p (base_1, base_2)) + if (!rtx_equal_p (base_1, base_2) || !rtx_equal_p (symbase_1, symbase_2)) return false; offval_1 = INTVAL (offset_1); -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer More tolerance and less prejudice are key for inclusion and diversity Excluding neuro-others for not behaving ""normal"" is *not* inclusive