[PATCH] D139193: [PowerPC] remove XXSWAPD after vector splat immediate

Ting Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 04:42:30 PST 2022


tingwang created this revision.
tingwang added reviewers: shchenz, nemanjai, PowerPC.
tingwang added a project: LLVM.
Herald added subscribers: kbarton, hiraditya.
Herald added a project: All.
tingwang requested review of this revision.
Herald added a subscriber: llvm-commits.

Redundant XXSWAPD has been observed on little-endian in D138883 <https://reviews.llvm.org/D138883> test case. Remove those associated with vector splat instructions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139193

Files:
  llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
  llvm/test/CodeGen/PowerPC/memset-tail.ll


Index: llvm/test/CodeGen/PowerPC/memset-tail.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/memset-tail.ll
+++ llvm/test/CodeGen/PowerPC/memset-tail.ll
@@ -192,9 +192,8 @@
 ; P8-LE:       # %bb.0: # %entry
 ; P8-LE-NEXT:    vspltisb 2, 15
 ; P8-LE-NEXT:    li 4, 16
-; P8-LE-NEXT:    xxswapd 0, 34
 ; P8-LE-NEXT:    stxsdx 34, 3, 4
-; P8-LE-NEXT:    stxvd2x 0, 0, 3
+; P8-LE-NEXT:    stxvd2x 34, 0, 3
 ; P8-LE-NEXT:    blr
 ;
 ; P9-LE-LABEL: memsetTailV1B8:
@@ -243,9 +242,8 @@
 ; P8-LE:       # %bb.0: # %entry
 ; P8-LE-NEXT:    vspltisb 2, 15
 ; P8-LE-NEXT:    li 4, 15
-; P8-LE-NEXT:    xxswapd 0, 34
 ; P8-LE-NEXT:    stxsdx 34, 3, 4
-; P8-LE-NEXT:    stxvd2x 0, 0, 3
+; P8-LE-NEXT:    stxvd2x 34, 0, 3
 ; P8-LE-NEXT:    blr
 ;
 ; P9-LE-LABEL: memsetTailV1B7:
@@ -296,9 +294,8 @@
 ; P8-LE:       # %bb.0: # %entry
 ; P8-LE-NEXT:    vspltisb 2, 15
 ; P8-LE-NEXT:    li 4, 16
-; P8-LE-NEXT:    xxswapd 0, 34
 ; P8-LE-NEXT:    stxsiwx 34, 3, 4
-; P8-LE-NEXT:    stxvd2x 0, 0, 3
+; P8-LE-NEXT:    stxvd2x 34, 0, 3
 ; P8-LE-NEXT:    blr
 ;
 ; P9-LE-LABEL: memsetTailV1B4:
@@ -350,9 +347,8 @@
 ; P8-LE:       # %bb.0: # %entry
 ; P8-LE-NEXT:    vspltisb 2, 15
 ; P8-LE-NEXT:    li 4, 15
-; P8-LE-NEXT:    xxswapd 0, 34
 ; P8-LE-NEXT:    stxsiwx 34, 3, 4
-; P8-LE-NEXT:    stxvd2x 0, 0, 3
+; P8-LE-NEXT:    stxvd2x 34, 0, 3
 ; P8-LE-NEXT:    blr
 ;
 ; P9-LE-LABEL: memsetTailV1B3:
Index: llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
+++ llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
@@ -638,6 +638,19 @@
           DefMI->getOperand(0).setReg(MI.getOperand(0).getReg());
           LLVM_DEBUG(dbgs() << "Removing redundant splat: ");
           LLVM_DEBUG(MI.dump());
+        } else if (Immed == 2 &&
+                   (DefOpc == PPC::VSPLTISB || DefOpc == PPC::VSPLTISH ||
+                    DefOpc == PPC::VSPLTISW)) {
+          // Swap of a vector splat immediate, convert to copy.
+          ToErase = &MI;
+          Simplified = true;
+          LLVM_DEBUG(
+              dbgs()
+              << "Optimizing swap(vspltis[b|h|w]) => copy(vspltis[b|h|w]): ");
+          LLVM_DEBUG(MI.dump());
+          BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(PPC::COPY),
+                  MI.getOperand(0).getReg())
+              .add(MI.getOperand(1));
         }
         break;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139193.479599.patch
Type: text/x-patch
Size: 2453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221202/d512949f/attachment.bin>


More information about the llvm-commits mailing list