[llvm-branch-commits] [llvm] AArch64: Look through copies in CCMP converter. (PR #186842)

Peter Collingbourne via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Mar 16 21:18:51 PDT 2026


https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/186842

>From e0d358f5b67dc3927554bfd205a22ba71acce29a Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Mon, 16 Mar 2026 21:18:36 -0700
Subject: [PATCH] Address review comment

Created using spr 1.3.6-beta.1
---
 .../AArch64/AArch64ConditionalCompares.cpp    | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
index a3d5ae60b89a7..06a88ba3da8dd 100644
--- a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
@@ -209,6 +209,17 @@ class SSACCmpConv {
 };
 } // end anonymous namespace
 
+static Register lookThroughCopies(Register Reg, MachineRegisterInfo *MRI) {
+  MachineInstr *MI;
+  while ((MI = MRI->getUniqueVRegDef(Reg)) &&
+         MI->getOpcode() == TargetOpcode::COPY) {
+    if (MI->getOperand(1).getReg().isPhysical())
+      break;
+    Reg = MI->getOperand(1).getReg();
+  }
+  return Reg;
+}
+
 // Check that all PHIs in Tail are selecting the same value from Head and CmpBB.
 // This means that no if-conversion is required when merging CmpBB into Head.
 bool SSACCmpConv::trivialTailPHIs() {
@@ -219,14 +230,7 @@ bool SSACCmpConv::trivialTailPHIs() {
     // PHI operands come in (VReg, MBB) pairs.
     for (unsigned oi = 1, oe = I.getNumOperands(); oi != oe; oi += 2) {
       MachineBasicBlock *MBB = I.getOperand(oi + 1).getMBB();
-      Register Reg = I.getOperand(oi).getReg();
-      MachineInstr *MI;
-      while ((MI = MRI->getUniqueVRegDef(Reg)) &&
-             MI->getOpcode() == TargetOpcode::COPY) {
-        if (MI->getOperand(1).getReg().isPhysical())
-          break;
-        Reg = MI->getOperand(1).getReg();
-      }
+      Register Reg = lookThroughCopies(I.getOperand(oi).getReg(), MRI);
       if (MBB == Head) {
         assert((!HeadReg || HeadReg == Reg) && "Inconsistent PHI operands");
         HeadReg = Reg;



More information about the llvm-branch-commits mailing list