[llvm] [PowerPC] Use rldimi/rlwimi to optimize build_vector (PR #67640)

Nemanja Ivanovic via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 26 12:46:18 PST 2023


================
@@ -9276,6 +9276,49 @@ bool llvm::checkConvertToNonDenormSingle(APFloat &ArgAPFloat) {
   return (!LosesInfo && !APFloatToConvert.isDenormal());
 }
 
+// Use rldimi/rlwimi to construct vectors:
+//   i32 = (i8 << 24) | (i8 << 16) | (i8 << 8) | i
+//   i32 = (i16 << 16) | i16
+//   i64 = (i32 << 32) | i32
+// And put two i64 together to get a vector.
+static SDValue tryMaskInsertVector(SDValue Op, SelectionDAG &DAG,
+                                   bool LittleEndian) {
+  EVT VT = Op.getValueType();
+  SDLoc dl(Op);
+
+  // There are already patterns for v4i32 and v2i64 construction.
+  if (VT == MVT::v16i8 || VT == MVT::v8i16) {
+    int NumElt = VT.getVectorNumElements();
+    int ScalarSize = VT.getScalarSizeInBits();
+    int EltsFor32 = NumElt / 4;
+    SDValue NewVecElts[4];
+    SDValue Parts[4];
+    for (int i = 0; i < 4; ++i) {
+      for (int j = 0; j < EltsFor32; ++j) {
+        SDValue Elt = LittleEndian
+                          ? Op.getOperand(i * EltsFor32 + EltsFor32 - j - 1)
----------------
nemanjai wrote:

These expressions are far from obvious. Please initialize variables with these expressions with comments explaining the expressions and then use the variables. The reader should not be forced to work out the details of this math without context.

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


More information about the llvm-commits mailing list