Skip to content

[BOLT][NFC] Simplify analyzeIndirectBranch #91662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 24, 2024

Conversation

aaupov
Copy link
Contributor

@aaupov aaupov commented May 9, 2024

Simplify mutually exclusive sanity checks in analyzeIndirectBranch,
where an UNKNOWN IndirectBranchType is to be returned. Reduces confusion
and code duplication when adding a new IndirectBranchType (to be added
in #91667).

Test Plan: NFC

aaupov added 2 commits May 9, 2024 14:43
Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented May 9, 2024

@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)

Changes

Simplify mutually exclusive sanity checks in analyzeIndirectBranch,
where an UNKNOWN IndirectBranchType is to be returned. Reduces confusion
and code duplication when adding a new IndirectBranchType (to be added
in a follow-up diff).

Test Plan: NFC


Full diff: https://github.com/llvm/llvm-project/pull/91662.diff

1 Files Affected:

  • (modified) bolt/lib/Target/X86/X86MCPlusBuilder.cpp (+9-7)
diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
index e7cabdabce90..86e7d4dfaed8 100644
--- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
+++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
@@ -2115,13 +2115,15 @@ class X86MCPlusBuilder : public MCPlusBuilder {
       return IndirectBranchType::POSSIBLE_FIXED_BRANCH;
     }
 
-    if (Type == IndirectBranchType::POSSIBLE_PIC_JUMP_TABLE &&
-        (MO->ScaleImm != 1 || MO->BaseRegNum != RIPRegister))
-      return IndirectBranchType::UNKNOWN;
-
-    if (Type != IndirectBranchType::POSSIBLE_PIC_JUMP_TABLE &&
-        MO->ScaleImm != PtrSize)
-      return IndirectBranchType::UNKNOWN;
+    switch (Type) {
+    case IndirectBranchType::POSSIBLE_PIC_JUMP_TABLE:
+      if (MO->ScaleImm != 1 || MO->BaseRegNum != RIPRegister)
+        return IndirectBranchType::UNKNOWN;
+      break;
+    default:
+      if (MO->ScaleImm != PtrSize)
+        return IndirectBranchType::UNKNOWN;
+    }
 
     MemLocInstrOut = MemLocInstr;
 

Copy link
Contributor

@rafaelauler rafaelauler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@aaupov aaupov changed the base branch from users/aaupov/spr/main.boltnfc-simplify-analyzeindirectbranch to main May 22, 2024 21:22
@aaupov aaupov changed the base branch from main to users/aaupov/spr/main.boltnfc-simplify-analyzeindirectbranch May 22, 2024 21:22
@aaupov aaupov changed the base branch from users/aaupov/spr/main.boltnfc-simplify-analyzeindirectbranch to main May 24, 2024 21:49
@aaupov aaupov merged commit be83f5c into main May 24, 2024
6 checks passed
@aaupov aaupov deleted the users/aaupov/spr/boltnfc-simplify-analyzeindirectbranch branch May 24, 2024 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants