On Wed, 2023-06-14 at 09:55 +0800, Jiufu Guo wrote: > Hi, > > Xi Ruoyao <xry...@xry111.site> writes: > > > On Tue, 2023-06-13 at 20:23 +0800, Jiufu Guo via Gcc-patches wrote: > > > > > Compare with previous version, this addes ChangeLog and removes > > > const_anchor parts. > > > https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621356.html. > > > > [Off topic] > > > > const_anchor is just broken now. See > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104843 and the thread > > beginning at > > https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591470.html. If > > you want to use it for rs6000 I guess you need to fix it first... > > Thanks so much for pointing out this. It seems about supporting > negative value, right? > > As you say: for 1. "g(0x8123ffff, 0x81240001)", it would be fine. > > The generated insns are: > (insn 5 2 6 2 (set (reg:DI 117) > (const_int -2128347135 [0xffffffff81240001])) "negative.c":5:3 681 > {*movdi_internal64} > (nil)) > (insn 6 5 7 2 (set (reg:DI 118) > (plus:DI (reg:DI 117) > (const_int -2 [0xfffffffffffffffe]))) "negative.c":5:3 66 > {*adddi3} > (expr_list:REG_EQUAL (const_int -2128347137 [0xffffffff8123ffff]) > (nil))) > > While for 2. "g (0x7fffffff, 0x80000001)", the generated rtl insns: > (insn 5 2 6 2 (set (reg:DI 117) > (const_int -2147483647 [0xffffffff80000001])) "negative.c":5:3 681 > {*movdi_internal64} > (nil)) > (insn 7 6 8 2 (set (reg:DI 3 3) > (const_int 2147483647 [0x7fffffff])) "negative.c":5:3 681 > {*movdi_internal64} > (nil)) > > The current const_anchor does not generate sth like: "r3 = r117 - 2" > But I would lean to say it is the limitation of current implementation: > "0xffffffff80000001" and "0x7fffffff" hit different anchors(even these > two values are 'close' on some aspect.)
The generic issue here is to fix (not "papering over") the signed overflow, we need to perform the addition in a target machine mode. We may always use Pmode (IIRC const_anchor was introduced for optimizing some constant addresses), but can we do better? Should we try addition in both DImode and SImode for a 64-bit capable machine? Or should we even try more operations than addition (for eg bit operations like xor or shift)? Doing so will need to create a new target hook for const anchoring, this is the "complete rework" I meant. -- Xi Ruoyao <xry...@xry111.site> School of Aerospace Science and Technology, Xidian University