Skip to content

Commit ce4491e

Browse files
committed
[BOLT][AArch64] Fixes assertion errors occurred when perf2bolt was executed
BOLT only checks for the most common indirect branch pattern during the branch analyzation. Extended the logic with two other indirect pattern which slightly differs from the expected one. Since these patterns are not related to JT, mark them as UNKNOWN branch. Fixes: #83114
1 parent d1a461d commit ce4491e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,16 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
707707
unsigned ShiftVal = AArch64_AM::getArithShiftValue(OperandExtension);
708708
AArch64_AM::ShiftExtendType ExtendType =
709709
AArch64_AM::getArithExtendType(OperandExtension);
710-
if (ShiftVal != 2)
711-
llvm_unreachable("Failed to match indirect branch! (fragment 2)");
710+
if (ShiftVal != 2) {
711+
// In this case the left shift amount is zero.
712+
// The range could be 0 to 4.
713+
// adr x6, 0x219fb0 <sigall_set+0x88>
714+
// add x6, x6, x14, lsl #2
715+
// ldr w7, [x6]
716+
// add x6, x6, w7, sxtw => no shift amount
717+
// br x6
718+
return false;
719+
}
712720

713721
if (ExtendType == AArch64_AM::SXTB)
714722
ScaleValue = 1LL;
@@ -753,6 +761,16 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
753761
return true;
754762
}
755763

764+
if (DefJTBaseAdd->getOpcode() == AArch64::ADR) {
765+
// Array indexing 'table branch'
766+
// adr x13, 0x215a18 <_nl_value_type_LC_COLLATE+0x50>
767+
// ldrh w13, [x13, w12, uxtw #1]
768+
// adr x12, 0x247b30 <__gettextparse+0x5b0>
769+
// add x13, x12, w13, sxth #2
770+
// br x13
771+
return false;
772+
}
773+
756774
assert(DefJTBaseAdd->getOpcode() == AArch64::ADDXri &&
757775
"Failed to match jump table base address pattern! (1)");
758776

0 commit comments

Comments
 (0)