Hi Richard, 在 2023/3/16 18:36, Richard Biener 写道: > On Thu, Mar 16, 2023 at 10:04 AM HAO CHEN GUI <guih...@linux.ibm.com> wrote: >> >> Hi Richard, >> >> 在 2023/3/16 15:57, Richard Biener 写道: >>> So this is one way around the lack of CSE/PRE of constant operands. I'd >>> argue that a better spot for this _might_ be LRA (split the constant out if >>> there's a free register available), postreload-[g]cse (CSE the constants) >>> and >>> then maybe cprop_hardreg to combine back single-use constants? >>> >>> I'm not sure if careful constraints massaging like adding magic letters to >>> alternatives with constants to pessimize them for LRA, making them >>> more expensive than spilling the constant to a register but avoid >>> secondary reloads with spilling a register to the stack to make room >>> for the constant, is possible - but in theory a special constraint modifier >>> for this purpose could be invented. >> >> Thanks so much for your advice. >> >> cse/gcse doesn't take cost of constant set (the def insn of the constant) >> into >> consideration. So it won't replace the register with a constant as it costs 1 >> insn with the register and costs 2 insn with the constant. > > I think it does (and should) cost the constant set (IIRC we had some > improvements > there, or at least proposed, during this stage1). But sure - this is why your > "trick" works. > It's doable if post-reload gsc costs the constant set. I will draft a patch to test it.
>> Finally, the single- >> use constants can't be back to 2 insn. > > And that's because of the issue you point out above? No. my original concern is the constant can't be back. If post-reload gsc doen't cost the constant set, the insn with a register always cost less than two insns with immediates. Commonly the constant set itself costs 2 insn also. > >> Not sure if I understand it correctly. >> Looking forward to your advice. > > My main point is that CSEing constants has impacts on register pressure > and thus should probably be done after or within register allocation. RTL > expansion itself is probably a bad time to pro-actively split out constants > even more if, as you say, nothing puts them back. > I agree. Thank a lot. > Richard. > >> Thanks >> Gui Haochen Gui Haochen