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

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 05:14:30 PDT 2025


================
@@ -1487,6 +1487,21 @@ AArch64InstrInfo::canRemovePTestInstr(MachineInstr *PTest, MachineInstr *Mask,
   bool PredIsPTestLike = isPTestLikeOpcode(PredOpcode);
   bool PredIsWhileLike = isWhileOpcode(PredOpcode);
 
+  uint64_t PredEltSize = 0;
+  if (PredIsWhileLike)
+    PredEltSize = getElementSizeForOpcode(PredOpcode);
+
+  if (Pred->isCopy()) {
+    // Instructions which return a multi-vector (e.g. WHILECC_x2) require copies
+    // before the branch to extract each subregister.
----------------
paulwalker-arm wrote:

Looking at `optimizePTestInstr` there's code to scan for CC uses between `PTest` and `Pred` so I don't think we can just look through a COPY like this.  Perhaps this code belongs in `optimizePTestInstr` so that `Pred` always points to the flag setting instruction?

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


More information about the llvm-commits mailing list