This is an archive of the discontinued LLVM Phabricator instance.

[mips] Reordering callseq* nodes to be linear
AbandonedPublic

Authored by abeserminji on Jan 12 2018, 2:21 AM.

Details

Reviewers
sdardis
petarj
Summary

When calling a function and passing large argument by value, and when argument size is above certain threshold, memcpy is used to copy argument on stack instead of sequence of loads and stores. In that case callseq* nodes for memcpy are nested inside callseq* nodes for the called function. This patch corrects this behavior by moving callseq_start of the called function after arguments calculation to temporary registers, so that callseq* nodes in resulting DAG are linear.

This is a second try to fix this problem. Previously reverted here rL316215.

Diff Detail

Event Timeline

abeserminji created this revision.Jan 12 2018, 2:21 AM
sdardis requested changes to this revision.Jan 30 2018, 2:22 AM

This patch isn't correct, as you're not passing the pointer to the callee or filling the rest of the argument registers with the object being passed. This results in the callee and caller differing in their interpretation of the arguments. The following test case shows this behaviour:

struct S1 {
  char t[32000];
};

extern void f2(char);

void f(int b, struct S1 a) {
  f2(a.t[1] + (char)b) ;
}

void g(void) {
  struct S1 a;
  f(1, a);
}

This compiled with r310704 reverted has the correct IR in that the caller and callee agree that the second argument to f is a pointer to a byval structure argument, but g doesn't set $5 to the result of the memcpy:

addiu $4, $1, 16
addiu $1, $fp, 32016
addiu $5, $1, 12
addiu $6, $zero, 32000
jal memcpy
nop
addiu $4, $zero, 1
sw  $2, 32012($fp)          # 4-byte Folded Spill
jal f
nop

while f believes that the second argument is spread across $5-$7:

addiu $sp, $sp, -32
sw  $ra, 28($sp)            # 4-byte Folded Spill
sw  $fp, 24($sp)            # 4-byte Folded Spill
move  $fp, $sp
sw  $7, 44($fp)
sw  $6, 40($fp)
sw  $5, 36($fp)
sw  $4, 20($fp)
lbu $4, 37($fp)
lw  $5, 20($fp)
addu  $4, $4, $5
seb $4, $4
jal f2

Can you take a look at this?

This revision now requires changes to proceed.Jan 30 2018, 2:22 AM