Jakub Jelinek <ja...@redhat.com> writes: > On Wed, Apr 16, 2014 at 11:43:12AM +0100, Richard Sandiford wrote: >> "X" was defined against reload, which always reloaded MEM addresses >> to follow the appropriate base and index register classes. This was >> done as a first pass before matching against the constraints: > > I think it would be fine if "X" had a MEM that isn't valid to replace > it say by (mem (scratch)) or similar. > What I think "X" is useful for is e.g. if you want to describe e.g. a > side-effect of inline-asm on certain location in memory, but don't really > need the address of that memory. Often "memory" is too big hammer, > people often say that certain inline-asm uses or sets or uses/sets or > clobbers say 100 byte long piece of memory somewhere, but the operand is > there solely to tell the compiler what memory it is. > I think "X" constraint is good for that if you aren't planning to actually > use the address anywhere. E.g. you call in inline-asm some function, > but the address construction is in the callee, there is no point to costly > compute the address in the caller (say for -fPIC).
If we want to replace the address with a scratch, I think we should do it at expand time so that all unneeded dependent code gets removed, rather than doing it only if the address isn't valid after optimisation. But since there's not AFAIK ever been a rule that "X" operands can't be printed, I think we should only do that if the operand isn't mentioned in the asm string. So would that be OK as a compromise? At expand time, check which operands are used (via get_referenced_operands). If an operand isn't used, is a MEM, has a constraint string that is exactly "X", and is not tied to other operands via matching constraints, replace the MEM address with (scratch). Then allow (mem (scratch)) as well as CONSTANT_P and general_operand in check_asm_operands? I suppose a follow-on optimisation would be to convert "m" into "X" in the same situation. Thanks, Richard