[llvm] [BOLT][NFC] Simplify analyzeIndirectBranch (PR #91662)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Fri May 24 14:50:20 PDT 2024
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/91662
>From 2392f0f58603f5d3ddb262b583558f4646ccb13b Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Thu, 9 May 2024 14:43:37 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
=?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
[skip ci]
---
bolt/lib/Target/X86/X86MCPlusBuilder.cpp | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
index 8b1894953f375..e7cabdabce901 100644
--- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
+++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
@@ -1932,6 +1932,19 @@ class X86MCPlusBuilder : public MCPlusBuilder {
// = R_X86_64_PC32(Ln) + En - JT
// = R_X86_64_PC32(Ln + offsetof(En))
//
+ auto isRIPRel = [&](X86MemOperand &MO) {
+ // NB: DispExpr should be set
+ return MO.DispExpr != nullptr &&
+ MO.BaseRegNum == RegInfo->getProgramCounter() &&
+ MO.IndexRegNum == X86::NoRegister &&
+ MO.SegRegNum == X86::NoRegister;
+ };
+ auto isIndexed = [](X86MemOperand &MO, MCPhysReg R) {
+ // NB: IndexRegNum should be set.
+ return MO.IndexRegNum != X86::NoRegister && MO.BaseRegNum == R &&
+ MO.ScaleImm == 4 && MO.DispImm == 0 &&
+ MO.SegRegNum == X86::NoRegister;
+ };
LLVM_DEBUG(dbgs() << "Checking for PIC jump table\n");
MCInst *MemLocInstr = nullptr;
const MCInst *MovInstr = nullptr;
@@ -1965,9 +1978,8 @@ class X86MCPlusBuilder : public MCPlusBuilder {
std::optional<X86MemOperand> MO = evaluateX86MemoryOperand(Instr);
if (!MO)
break;
- if (MO->BaseRegNum != R1 || MO->ScaleImm != 4 ||
- MO->IndexRegNum == X86::NoRegister || MO->DispImm != 0 ||
- MO->SegRegNum != X86::NoRegister)
+ if (!isIndexed(*MO, R1))
+ // POSSIBLE_PIC_JUMP_TABLE
break;
MovInstr = &Instr;
} else {
@@ -1986,9 +1998,7 @@ class X86MCPlusBuilder : public MCPlusBuilder {
std::optional<X86MemOperand> MO = evaluateX86MemoryOperand(Instr);
if (!MO)
break;
- if (MO->BaseRegNum != RegInfo->getProgramCounter() ||
- MO->IndexRegNum != X86::NoRegister ||
- MO->SegRegNum != X86::NoRegister || MO->DispExpr == nullptr)
+ if (!isRIPRel(*MO))
break;
MemLocInstr = &Instr;
break;
More information about the llvm-commits
mailing list