[llvm] [AArch64][SVE2p1] Remove redundant PTESTs when predicate is a WHILEcc_x2 (PR #156478)

Kerry McLaughlin via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 02:42:56 PDT 2025


================
@@ -1613,6 +1613,15 @@ bool AArch64InstrInfo::optimizePTestInstr(
     const MachineRegisterInfo *MRI) const {
   auto *Mask = MRI->getUniqueVRegDef(MaskReg);
   auto *Pred = MRI->getUniqueVRegDef(PredReg);
+
+  if (Pred->isCopy() && PTest->getOpcode() == AArch64::PTEST_PP_FIRST) {
+    // Instructions which return a multi-vector (e.g. WHILECC_x2) require copies
+    // before the branch to extract each subregister.
+    auto Op = Pred->getOperand(1);
+    if (Op.isReg() && Op.getSubReg() == AArch64::psub0)
----------------
kmclaughlin-arm wrote:

I think it is required that the register is virtual. I was checking `isVirtual` previously when this was part of `canRemovePTestInstr`, but must have removed it when I moved this to `optimizePTestInstr`.

https://github.com/llvm/llvm-project/pull/156478


More information about the llvm-commits mailing list