From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id B7C073858D1E for ; Wed, 24 Jan 2024 07:51:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7C073858D1E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B7C073858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706082724; cv=none; b=vmTVIKOyNR0bIUG8pSjDEv97vTQHkILXJghIh/3dliewExeMgUNEP0MI68g9uvdNWYHaWZmRjIPsnc5uF24x8rK79fgunX0gh20UonEHus0fagsNBxhPm2oGfosjMejpQeROvRLkW2i8BbjcGF9WJjNUDT/qY/n4BkVLlkl2/50= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706082724; c=relaxed/simple; bh=72nujA5cy6b8+fNia8wans+znJIUyMJrSqDTdqZP9B4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=AtrFtdu/kh0EDsMg9ggfe9/oU+CSxdlalt39s26beG77sYFzRiTwTWqoJy6EmNqLz6Xi3+NDiKnCuJX3kg0OMTjEY7aiDhJfo4i1fkgUjAf0Rk3B3ktJFaXBrICt3rdJyTjY1DioEJErsSsbi1vt+/OhBAdK6HpHNIIgN/EEmdI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-50f11e3ba3aso7485482e87.1 for ; Tue, 23 Jan 2024 23:51:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1706082718; x=1706687518; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:cc:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=50neSqXoljadEdwTDtn1IY27mwoR+kC2Sa183SWjDaI=; b=Z7tpBQEfp7IOrf1Su/NqIIHT8SA+wm2LLF/5D2CnFJpLdwiQTeLP5LFzS4kRz4apEB nxyH44AHODyytMwkg/pmC7qO3mQ7k4wCyWAzIL2Lmsz/6faCp2B+YXuqgpROiFTNUWBA 5REfSpIX9hvOsBQFIGWJLlPOMSISJLuuGpK0RHF8+EVheU248e0EuKNoih47vMgMm2xM PEh083/Ji6gbvCPIPK6y2wT6CFFPXPJu0uLnDPjPPN7ZwaYBujSWSV3n/BPW14ERPIQp LS+WBVxWfu9gY/hj23rWymCgyqyMoKEBBklAjR+MLptHhh8PHEPNZudJWuCFmosr5qZE 3lew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706082718; x=1706687518; h=content-transfer-encoding:in-reply-to:autocrypt:from:cc:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=50neSqXoljadEdwTDtn1IY27mwoR+kC2Sa183SWjDaI=; b=uVcbl8UAWo9ByBN9LYkt1w8/xhzxJRzKuhbOjr/DtZ0Z172OEVV05d9vYxmFmKvzLu Jhc3aMJtLDhLAWjnab0eqiNPrhkIBMpPOyz0gPNMSTTAwGAZJWk5lcORjm1O6dln9NeB 9X/YXRq1QWPi+Bb3kWudwaWJPg9O5zFERqLahD44pxHNTw9REq4X3eJC7wfiaSna0uBF Vyy9MN9A2uXVob1GJVpOVKaK46SMA0N18ill+Etwerohksue8xnd7xYg9t7zTiu0/PfG X/GpsPSMg6+dUicW/+B8+rq6CWX/3cI07uc1uGTrN07WGlJep9QIYE7USFm6FvLKKqv5 nsgA== X-Gm-Message-State: AOJu0YztWalOtVHOz0HA0le8i6HR9EuJ0P7tTyYkgTyTrgBvW40lY11+ 5bA/ewi7tQwfXiUinDuvLVO026gNESmEmElZOiODi39MMgPSILHVjdiQIHMXMg== X-Google-Smtp-Source: AGHT+IGsdZ6bBI7POZInthrybAegVRxiDCs/qpppPtOsGLdO6y4c5+xpU2PMSQwXHyEu9irnDuBO2A== X-Received: by 2002:a2e:bc0f:0:b0:2cd:cfb3:50d0 with SMTP id b15-20020a2ebc0f000000b002cdcfb350d0mr659396ljf.98.1706082718204; Tue, 23 Jan 2024 23:51:58 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id i9-20020a05663813c900b0046e760beffesm4012533jaj.19.2024.01.23.23.51.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jan 2024 23:51:57 -0800 (PST) Message-ID: <2c745a10-04f5-4994-a627-ea434218a823@suse.com> Date: Wed, 24 Jan 2024 08:51:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH,V2] gas: x86: ginsn: adjust ginsns for certain lea ops Content-Language: en-US To: Indu Bhagat References: <20240124064046.1191952-1-indu.bhagat@oracle.com> Cc: binutils@sourceware.org From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4H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Fkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <20240124064046.1191952-1-indu.bhagat@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3025.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 24.01.2024 07:40, Indu Bhagat wrote: > @@ -5664,76 +5666,64 @@ x86_ginsn_lea (const symbolS *insn_end_sym) > { > offsetT src_disp = 0; > ginsnS *ginsn = NULL; > - unsigned int base_reg; > - unsigned int index_reg; > + unsigned int src1_reg; > + const reg_entry *src1; > offsetT index_scale; > unsigned int dst_reg; > > if (!i.index_reg && !i.base_reg) > { > - /* lea symbol, %rN. */ > - dst_reg = ginsn_dw2_regnum (i.op[1].regs); > - /* TBD_GINSN_INFO_LOSS - Skip encoding information about the symbol. */ > - ginsn = ginsn_new_mov (insn_end_sym, false, > - GINSN_SRC_IMM, 0xf /* arbitrary const. */, 0, > - GINSN_DST_REG, dst_reg, 0); > + if (i.disp_operands && i.op[0].disps->X_op == O_constant) > + { > + /* lea const, %rN. */ > + src_disp = i.op[0].disps->X_add_number; > + dst_reg = ginsn_dw2_regnum (i.op[1].regs); > + ginsn = ginsn_new_mov (insn_end_sym, false, > + GINSN_SRC_IMM, 0, src_disp, > + GINSN_DST_REG, dst_reg, 0); > + ginsn_set_where (ginsn); > + } Since earlier on you've been mentioning that you primarily target insn forms actually in use in existing code, I wonder whether you've ever seen any use of this. The same is better (shorter) expressed by MOV, and hence I'd expect people to prefer that form. IOW the question here is: Is there much value in having this code, rather than simply penalizing people bogusly using such by having this case end at the common x86_ginsn_unhandled path as well. > + /* Skip handling lea symbol, %rN here. Deal with it in the > + x86_ginsn_unhandled code path. TBD_GINSN_GEN_NOT_SCFI. */ > } > - else if (i.base_reg && !i.index_reg) > + else if ((i.base_reg && !i.index_reg) > + || (!i.base_reg && i.index_reg)) I frequently see conditionals like this written this way. Maybe it's indeed clearer to a majority; personally I'd prefer the shorter else if (!i.base_reg != !i.index_reg) However, considering the earlier if() this is an else-if to, even else if (!i.base_reg || !i.index_reg) would also suffice (but as per above that if() may want to go away). > { > - /* lea -0x2(%base),%dst. */ > - base_reg = ginsn_dw2_regnum (i.base_reg); > - dst_reg = ginsn_dw2_regnum (i.op[1].regs); > + /* lea disp(%base) %dst or lea disp(,%index,imm) %dst. */ Would be nice if the missing commas were added here. > - if (i.disp_operands) > - src_disp = i.op[0].disps->X_add_number; > - > - if (src_disp) > - /* Generate an ADD ginsn. */ > - ginsn = ginsn_new_add (insn_end_sym, true, > - GINSN_SRC_REG, base_reg, 0, > - GINSN_SRC_IMM, 0, src_disp, > - GINSN_DST_REG, dst_reg, 0); > - else > - /* Generate a MOV ginsn. */ > - ginsn = ginsn_new_mov (insn_end_sym, true, > - GINSN_SRC_REG, base_reg, 0, > - GINSN_DST_REG, dst_reg, 0); > - } > - else if (!i.base_reg && i.index_reg) > - { > - /* lea (,%index,imm), %dst. */ > - /* TBD_GINSN_INFO_LOSS - There is no explicit ginsn multiply operation, > - instead use GINSN_TYPE_OTHER. Also, note that info about displacement > - is not carried forward either. But this is fine because > - GINSN_TYPE_OTHER will cause SCFI pass to bail out any which way if > - dest reg is interesting. */ > index_scale = i.log2_scale_factor; > - index_reg = ginsn_dw2_regnum (i.index_reg); > + src1 = (i.base_reg) ? i.base_reg : i.index_reg; > + src1_reg = ginsn_dw2_regnum (src1); Since I can't spot any other use of src1, why not simply src1_reg = ginsn_dw2_regnum (i.base_reg ? i.base_reg : i.index_reg); ? Otherwise at the very least please omit the pointless parentheses in the conditional expression. > dst_reg = ginsn_dw2_regnum (i.op[1].regs); > - ginsn = ginsn_new_other (insn_end_sym, true, > - GINSN_SRC_REG, index_reg, > - GINSN_SRC_IMM, index_scale, > - GINSN_DST_REG, dst_reg); > - /* FIXME - It seems to make sense to represent a scale factor of 1 > - correctly here (i.e. not as "other", but rather similar to the > - base-without- index case above)? */ > - } > - else > - { > - /* lea disp(%base,%index,imm) %dst. */ > - /* TBD_GINSN_INFO_LOSS - Skip adding information about the disp and imm > - for index reg. */ > - base_reg = ginsn_dw2_regnum (i.base_reg); > - index_reg = ginsn_dw2_regnum (i.index_reg); > - dst_reg = ginsn_dw2_regnum (i.op[1].regs); > - /* Generate an GINSN_TYPE_OTHER ginsn. */ > - ginsn = ginsn_new_other (insn_end_sym, true, > - GINSN_SRC_REG, base_reg, > - GINSN_SRC_REG, index_reg, > - GINSN_DST_REG, dst_reg); > - } > + /* It makes sense to represent a scale factor of 1 precisely here > + (i.e., not using GINSN_TYPE_OTHER, but rather similar to the > + base-without-index case). Ignore the case when disp has a symbol > + instead. */ > + if (!index_scale > + && (!i.disp_operands > + || (i.disp_operands && i.op[0].disps->X_op == O_constant))) This is functionally identical to the shorter if (!index_scale && (!i.disp_operands || i.op[0].disps->X_op == O_constant)) But: What about any of lea (%rax,%riz),%rbp lea (%rax,4),%rbp lea (%rax,%riz,4),%rbp ? Jan