@@ -2159,8 +2159,115 @@ let AddedComplexity = 400, Predicates = [IsISA3_1, HasVSX] in {
2159
2159
(COPY_TO_REGCLASS $VRB, VSRC), 2)))>;
2160
2160
}
2161
2161
2162
- class XXEvalPattern <dag pattern, bits<8> imm> :
2163
- Pat<(v4i32 pattern), (XXEVAL $vA, $vB, $vC, imm)> {}
2162
+ // =============================================================================
2163
+ // XXEVAL Instruction Pattern Definitions
2164
+ // =============================================================================
2165
+ //
2166
+ // XXEVAL instruction performs 256 different logical operations on three vector
2167
+ // operands using an 8-bit immediate value to select the operation.
2168
+ // Format: xxeval XT, XA, XB, XC, IMM
2169
+ // For example:
2170
+ // Equivalent function A?xor(B,C):and(B,C) is performed by
2171
+ // xxeval XT, XA, XB, XC, 22
2172
+ //
2173
+ // REGISTER CLASS CONSTRAINTS:
2174
+ // - XXEVAL natively supports: VSRC register class [v4i32, v4f32, v2f64, v2i64]
2175
+ // - Other vector types [v16i8, v8i16] require COPY_TO_REGCLASS to/from VRRC
2176
+ // =============================================================================
2177
+
2178
+ class XXEvalPattern<dag pattern, bits<8> imm>
2179
+ : Pat<(v4i32 pattern), (XXEVAL $vA, $vB, $vC, imm)> {}
2180
+
2181
+ class XXEvalPatterns<ValueType Vt, dag InputPattern, bits<8> Imm>
2182
+ : Pat<(Vt InputPattern),
2183
+ !if(!or(!eq(Vt, v4i32), !eq(Vt, v2i64)),
2184
+ // VSRC path: direct XXEVAL for v4i32 and v2i64
2185
+ (XXEVAL $vA, $vB, $vC, Imm),
2186
+ // VRRC path: wrap with COPY_TO_REGCLASS for other types
2187
+ (COPY_TO_REGCLASS(XXEVAL(COPY_TO_REGCLASS Vt:$vA, VSRC),
2188
+ (COPY_TO_REGCLASS Vt:$vB, VSRC),
2189
+ (COPY_TO_REGCLASS Vt:$vC, VSRC), Imm),
2190
+ VRRC))> {}
2191
+
2192
+ // =============================================================================
2193
+ // PatFrags for Bitcast-Aware Vector bitwise Operations
2194
+ //
2195
+ // Each PatFrags defines TWO alternatives for pattern matcher to choose:
2196
+ // - Direct operation (for v4i32)
2197
+ // - Bitcast operation (for other types: v2i64, v16i8, v8i16)
2198
+ // =============================================================================
2199
+
2200
+ // Basic Binary Operations
2201
+ def VAnd
2202
+ : PatFrags<(ops node:$a, node:$b), [(and node:$a, node:$b),
2203
+ (bitconvert(and
2204
+ (v4i32(bitconvert node:$a)),
2205
+ (v4i32(bitconvert node:$b))))]>;
2206
+
2207
+ def VXor
2208
+ : PatFrags<(ops node:$a, node:$b), [(xor node:$a, node:$b),
2209
+ (bitconvert(xor
2210
+ (v4i32(bitconvert node:$a)),
2211
+ (v4i32(bitconvert node:$b))))]>;
2212
+
2213
+ def VOr : PatFrags<(ops node:$a, node:$b), [(or node:$a, node:$b),
2214
+ (bitconvert(or
2215
+ (v4i32(bitconvert node:$a)),
2216
+ (v4i32(bitconvert node:$b))))]>;
2217
+
2218
+ def VNot
2219
+ : PatFrags<(ops node:$a), [(vnot node:$a),
2220
+ (bitconvert(vnot(v4i32(bitconvert node:$a))))]>;
2221
+
2222
+ // Derived bitwise operations
2223
+ // Vector NOR operation (not(or))
2224
+ def VNor
2225
+ : PatFrags<(ops node:$a, node:$b), [(vnot(or node:$a, node:$b)),
2226
+ (bitconvert(vnot(or
2227
+ (v4i32(bitconvert node:$a)),
2228
+ (v4i32(bitconvert node:$b)))))]>;
2229
+
2230
+ // Vector EQV operation (not(xor))
2231
+ def VEqv
2232
+ : PatFrags<(ops node:$a, node:$b), [(vnot(xor node:$a, node:$b)),
2233
+ (bitconvert(vnot(xor
2234
+ (v4i32(bitconvert node:$a)),
2235
+ (v4i32(bitconvert node:$b)))))]>;
2236
+
2237
+ // =============================================================================
2238
+ // XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectAnd
2239
+ // This class matches the equivalent Ternary Operation: A ? f(B,C) : AND(B,C)
2240
+ // and emit the corresponding xxeval instruction with the imm value.
2241
+ //
2242
+ // The patterns implement xxeval vector select operations where:
2243
+ // - A is the selector vector
2244
+ // - f(B,C) is the "true" case op on vectors B and C (XOR, NOR, EQV, or NOT)
2245
+ // - AND(B,C) is the "false" case op on vectors B and C
2246
+ // =============================================================================
2247
+ multiclass XXEvalTernarySelectAnd<ValueType Vt> {
2248
+ // Pattern: A ? XOR(B,C) : AND(B,C) XXEVAL immediate value: 22
2249
+ def : XXEvalPatterns<
2250
+ Vt, (vselect Vt:$vA, (VXor Vt:$vB, Vt:$vC), (VAnd Vt:$vB, Vt:$vC)),
2251
+ 22>;
2252
+
2253
+ // Pattern: A ? NOR(B,C) : AND(B,C) XXEVAL immediate value: 24
2254
+ def : XXEvalPatterns<
2255
+ Vt, (vselect Vt:$vA, (VNor Vt:$vB, Vt:$vC), (VAnd Vt:$vB, Vt:$vC)),
2256
+ 24>;
2257
+
2258
+ // Pattern: A ? EQV(B,C) : AND(B,C) XXEVAL immediate value: 25
2259
+ def : XXEvalPatterns<
2260
+ Vt, (vselect Vt:$vA, (VEqv Vt:$vB, Vt:$vC), (VAnd Vt:$vB, Vt:$vC)),
2261
+ 25>;
2262
+
2263
+ // Pattern: A ? NOT(C) : AND(B,C) XXEVAL immediate value: 26
2264
+ def : XXEvalPatterns<
2265
+ Vt, (vselect Vt:$vA, (VNot Vt:$vC), (VAnd Vt:$vB, Vt:$vC)), 26>;
2266
+
2267
+ // Pattern: A ? NOT(B) : AND(B,C) XXEVAL immediate value: 28
2268
+ def : XXEvalPatterns<
2269
+ Vt, (vselect Vt:$vA, (VNot Vt:$vB), (VAnd Vt:$vB, Vt:$vC)), 28>;
2270
+ }
2164
2271
2165
2272
let Predicates = [PrefixInstrs, HasP10Vector] in {
2166
2273
let AddedComplexity = 400 in {
@@ -2270,6 +2377,11 @@ let Predicates = [PrefixInstrs, HasP10Vector] in {
2270
2377
// (xor A, (or B, C))
2271
2378
def : XXEvalPattern<(xor v4i32:$vA, (or v4i32:$vB, v4i32:$vC)), 120>;
2272
2379
2380
+ // XXEval Patterns for ternary Operations.
2381
+ foreach Ty = [v4i32, v2i64, v8i16, v16i8] in {
2382
+ defm : XXEvalTernarySelectAnd<Ty>;
2383
+ }
2384
+
2273
2385
// Anonymous patterns to select prefixed VSX loads and stores.
2274
2386
// Load / Store f128
2275
2387
def : Pat<(f128 (load PDForm:$src)),
0 commit comments