This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Move the branch relaxation pass after BTI insertion
ClosedPublic

Authored by chill on Oct 17 2019, 10:01 AM.

Details

Summary

Inserting BTI instructions can push branch destinations out of range.

The branch relaxation pass itself cannot insert indirect branches since TargetInstrInfo::insertIndirecrtBranch is not implemented for AArch64 (guess +/-128 MB direct branch range is more than enough in practice).

Testing this is a bit tricky.

The original test case we have is 155kloc/6.1M. I've generated a test case using this program:

#include <iostream>

int main() {
  std::cout << R"src(int test();
void g0(), g1(), g2(), g3(), g4(), e();

void f(int v) {
  if ((test() & 2) == 0) {
  switch (v) {
  case 0: 
    g0();
  case 1:
    g1();
  case 2:
    g2();
  case 3:
    g3();
  }
)src";

  const int N = 8176;

  for (int i = 0; i < N; ++i)
    std::cout << "    void h" << i << "();\n";
  for (int i = 0; i < N; ++i)
    std::cout << "    h" << i << "();\n";

  std::cout << R"src(
  } else {
    e();
  }
}
)src";
}

which is still a bit too much to commit as a regression test, IMHO.

Diff Detail

Event Timeline

chill created this revision.Oct 17 2019, 10:01 AM
chill updated this revision to Diff 225458.Oct 17 2019, 10:09 AM

Updated pipeline tests.

For testing, we have the SPACE pseudo-instruction, which can be used to emulate very large basic blocks, maybe you could reduce your reproducer using that?

chill updated this revision to Diff 225665.Oct 18 2019, 10:43 AM

For testing, we have the SPACE pseudo-instruction, which can be used to emulate very large basic blocks, maybe you could reduce your reproducer using that?

Thanks for the tip!

This revision is now accepted and ready to land.Oct 21 2019, 6:10 PM
chill updated this revision to Diff 227485.Nov 1 2019, 10:58 AM

Rebase, retest.
A wild CFGuardLongjmpPass appeared in the meantime, but it does not create instructions, only symbols, AFAICT, so
its placement is fine.

This revision was automatically updated to reflect the committed changes.