[PATCH] D32563: Add LiveRangeShrink pass to shrink live range within BB.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue May 2 13:41:42 PDT 2017
Wei and I spent some time on the MachineScheduler.cpp and have some
findings. First, if we want to work at machine code level, the
original small testcase is not good enough to show the problem. The
new testcase is attached at the end of the email.
In this testcase, if we build without the patch, there will be a lot
register spill as all the "add" operation are sinked down, causing
significant register pressure increase. The patch in the current form
can fix the problem.
If we want to fix this in misched, we first need to disable setting
call as scheduling boundary. Even with that, with the default
bottom-up scheduling, the heuristic only moves the "add"s related to
"foo()" up. "add"s related to "goo()" are still computed in the
bottom. The top-down scheduling algorithm can move "add" close to the
definition, thus can generate the same efficient code as this patch.
>From the above observation, we think that it would be hard to make a
perfect heuristic in misched to model live-range impact precisely.
Additionally, schedule instructions across call boundary may be hard
to get right (if we simply disable call-boundary, it introduces
runtime error). So misched may not be the best place for this
transformation. Maybe we should put it in peephole?
Any suggestions on how to proceed?
Thanks,
Dehao
test.cc:
unsigned foo();
unsigned goo();
void test() {
unsigned long total_size = 0;
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
{
unsigned long data_size = 0;
unsigned int count = foo();
data_size = 4UL * count;
total_size += 2 * goo();
total_size += data_size;
}
__builtin_printf("total_size = %lu\n", total_size);
}
More information about the llvm-commits
mailing list