Skip to content

Commit 87129cf

Browse files
tonykuttaiTony Varghese
andauthored
[PowerPC] Exploit xxeval instruction for operations of the form ternary(A,X, XOR(B,C)) and ternary(A,X, OR(B,C)) (#157909)
Adds support for ternary equivalent operations of the form - `ternary(A, X, xor(B,C))` where `X=[and(B,C)| nor(B,C)| or(B,C)| B | C]`. - `ternary(A, X, or(B,C))` where `X = [and(B,C)| eqv(B,C)| not(B)| not(C)| nand(B,C)| B | C]`. The following are the patterns involved and the imm values: ``` ternary(A, and(B,C), xor(B,C)) 97 ternary(A, B, xor(B,C)) 99 ternary(A, C, xor(B,C)) 101 ternary(A, or(B,C), xor(B,C)) 103 ternary(A, nor(B,C), xor(B,C)) 104 ternary(A, and(B,C), or(B,C)) 113 ternary(A, B, or(B,C)) 115 ternary(A, C, or(B,C)) 117 ternary(A, eqv(B,C), or(B,C)) 121 ternary(A, not(C), or(B,C)) 122 ternary(A, not(B), or(B,C)) 124 ternary(A, nand(B,C), or(B,C)) 126 ``` eg. `xxeval XT, XA, XB, XC, 97` performs the ternary operation: `XA ? and(XB, XC) : xor(XB, XC)` and places the result in `XT`. This is the continuation of: - [[PowerPC] Exploit xxeval instruction for ternary patterns - ternary(A, X, and(B,C))](#141733 (comment)) - [[PowerPC] Exploit xxeval instruction for operations of the form ternary(A,X,B) and ternary(A,X,C).](#152956 (comment)) --------- Co-authored-by: Tony Varghese <[email protected]>
1 parent e40bbba commit 87129cf

File tree

4 files changed

+139
-133
lines changed

4 files changed

+139
-133
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.

llvm/test/CodeGen/PowerPC/xxeval-vselect-x-eqv.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ define <4 x i32> @ternary_A_not_C_eqv_BC_4x32(<4 x i1> %A, <4 x i32> %B, <4 x i3
174174
; CHECK: # %bb.0: # %entry
175175
; CHECK-NEXT: xxleqv v5, v5, v5
176176
; CHECK-NEXT: xxlnor vs0, v4, v4
177-
; CHECK-NEXT: xxleqv vs1, v4, v3
178177
; CHECK-NEXT: vslw v2, v2, v5
179178
; CHECK-NEXT: vsraw v2, v2, v5
180-
; CHECK-NEXT: xxsel v2, vs1, vs0, v2
179+
; CHECK-NEXT: xxeval v2, v2, vs0, v3, 99
181180
; CHECK-NEXT: blr
182181
entry:
183182
%not = xor <4 x i32> %C, <i32 -1, i32 -1, i32 -1, i32 -1> ; Vector not operation

0 commit comments

Comments
 (0)