Skip to content

Commit 6f852c3

Browse files
author
Tony Varghese
committed
Exploit xxeval instruction for operations of the form ternary(A, X, XOR(B,C)) and ternary(A, X, OR(B,C))
1 parent cecdff9 commit 6f852c3

File tree

3 files changed

+138
-131
lines changed

3 files changed

+138
-131
lines changed

llvm/lib/Target/PowerPC/PPCInstrP10.td

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,91 @@ multiclass XXEvalTernarySelectC<ValueType Vt>{
23262326
def : XXEvalPattern<Vt, (vselect Vt:$vA, (VNand Vt:$vB, Vt:$vC), Vt:$vC), 94>;
23272327
}
23282328

2329+
// =============================================================================
2330+
// XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectXor
2331+
// This class matches the equivalent Ternary Operation: A ? f(B,C) : XOR(B,C)
2332+
// and emit the corresponding xxeval instruction with the imm value.
2333+
//
2334+
// The patterns implement xxeval vector select operations where:
2335+
// - A is the selector vector
2336+
// - f(B,C) is the "true" case op in set {B, C, AND(B,C), OR(B,C), NOR(B,C)}
2337+
// - XOR(B,C) is the "false" case op on vectors B and C
2338+
// =============================================================================
2339+
multiclass XXEvalTernarySelectXor<ValueType Vt> {
2340+
// Pattern: A ? AND(B,C) : XOR(B,C) XXEVAL immediate value: 97
2341+
def : XXEvalPattern<
2342+
Vt, (vselect Vt:$vA, (VAnd Vt:$vB, Vt:$vC), (VXor Vt:$vB, Vt:$vC)),
2343+
97>;
2344+
2345+
// Pattern: A ? B : XOR(B,C) XXEVAL immediate value: 99
2346+
def : XXEvalPattern<
2347+
Vt, (vselect Vt:$vA, Vt:$vB, (VXor Vt:$vB, Vt:$vC)),
2348+
99>;
2349+
2350+
// Pattern: A ? C : XOR(B,C) XXEVAL immediate value: 101
2351+
def : XXEvalPattern<
2352+
Vt, (vselect Vt:$vA, Vt:$vC, (VXor Vt:$vB, Vt:$vC)),
2353+
101>;
2354+
2355+
// Pattern: A ? OR(B,C) : XOR(B,C) XXEVAL immediate value: 103
2356+
def : XXEvalPattern<
2357+
Vt, (vselect Vt:$vA, (VOr Vt:$vB, Vt:$vC), (VXor Vt:$vB, Vt:$vC)),
2358+
103>;
2359+
2360+
// Pattern: A ? NOR(B,C) : XOR(B,C) XXEVAL immediate value: 104
2361+
def : XXEvalPattern<
2362+
Vt, (vselect Vt:$vA, (VNor Vt:$vB, Vt:$vC), (VXor Vt:$vB, Vt:$vC)),
2363+
104>;
2364+
}
2365+
2366+
// =============================================================================
2367+
// XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectOr
2368+
// This class matches the equivalent Ternary Operation: A ? f(B,C) : OR(B,C)
2369+
// and emit the corresponding xxeval instruction with the imm value.
2370+
//
2371+
// The patterns implement xxeval vector select operations where:
2372+
// - A is the selector vector
2373+
// - f(B,C) is the "true" case op in set {B, C, AND(B,C), EQV(B,C), NOT(B),
2374+
// NOT(C), NAND(B,C)}
2375+
// - OR(B,C) is the "false" case op on vectors B and C
2376+
// =============================================================================
2377+
multiclass XXEvalTernarySelectOr<ValueType Vt> {
2378+
// Pattern: A ? AND(B,C) : OR(B,C) XXEVAL immediate value: 113
2379+
def : XXEvalPattern<
2380+
Vt, (vselect Vt:$vA, (VAnd Vt:$vB, Vt:$vC), (VOr Vt:$vB, Vt:$vC)),
2381+
113>;
2382+
2383+
// Pattern: A ? B : OR(B,C) XXEVAL immediate value: 115
2384+
def : XXEvalPattern<
2385+
Vt, (vselect Vt:$vA, Vt:$vB, (VOr Vt:$vB, Vt:$vC)),
2386+
115>;
2387+
2388+
// Pattern: A ? C : OR(B,C) XXEVAL immediate value: 117
2389+
def : XXEvalPattern<
2390+
Vt, (vselect Vt:$vA, Vt:$vC, (VOr Vt:$vB, Vt:$vC)),
2391+
117>;
2392+
2393+
// Pattern: A ? EQV(B,C) : OR(B,C) XXEVAL immediate value: 121
2394+
def : XXEvalPattern<
2395+
Vt, (vselect Vt:$vA, (VEqv Vt:$vB, Vt:$vC), (VOr Vt:$vB, Vt:$vC)),
2396+
121>;
2397+
2398+
// Pattern: A ? NOT(C) : OR(B,C) XXEVAL immediate value: 122
2399+
def : XXEvalPattern<
2400+
Vt, (vselect Vt:$vA, (VNot Vt:$vC), (VOr Vt:$vB, Vt:$vC)),
2401+
122>;
2402+
2403+
// Pattern: A ? NOT(B) : OR(B,C) XXEVAL immediate value: 124
2404+
def : XXEvalPattern<
2405+
Vt, (vselect Vt:$vA, (VNot Vt:$vB), (VOr Vt:$vB, Vt:$vC)),
2406+
124>;
2407+
2408+
// Pattern: A ? NAND(B,C) : OR(B,C) XXEVAL immediate value: 126
2409+
def : XXEvalPattern<
2410+
Vt, (vselect Vt:$vA, (VNand Vt:$vB, Vt:$vC), (VOr Vt:$vB, Vt:$vC)),
2411+
126>;
2412+
}
2413+
23292414
let Predicates = [PrefixInstrs, HasP10Vector] in {
23302415
let AddedComplexity = 400 in {
23312416
def : Pat<(v4i32 (build_vector i32immNonAllOneNonZero:$A,
@@ -2438,7 +2523,9 @@ let Predicates = [PrefixInstrs, HasP10Vector] in {
24382523
foreach Ty = [v4i32, v2i64, v8i16, v16i8] in {
24392524
defm : XXEvalTernarySelectAnd<Ty>;
24402525
defm : XXEvalTernarySelectB<Ty>;
2441-
defm : XXEvalTernarySelectC<Ty>;
2526+
defm : XXEvalTernarySelectC<Ty>;
2527+
defm : XXEvalTernarySelectXor<Ty>;
2528+
defm : XXEvalTernarySelectOr<Ty>;
24422529
}
24432530

24442531
// Anonymous patterns to select prefixed VSX loads and stores.

0 commit comments

Comments
 (0)