Skip to content

Commit d83fe12

Browse files
tonykuttaiTony Varghese
andauthored
[PowerPC] Exploit xxeval instruction for operations of the form ternary(A, X, nor(B,C)), ternary(A, X, eqv(B,C)), ternary(A, X, nand(B,C)), ternary(A, X, not(B)) and ternary(A, X, not(C)) (#158096)
Adds support for ternary equivalent operations of the form `ternary(A, X, nor(B,C))`, `ternary(A, X, eqv(B,C))`, `ternary(A, X, nand(B,C))`, `ternary(A, X, not(B))` and `ternary(A, X, not(C))` where `X=[xor(B,C)| nor(B,C)| eqv(B,C)| not(B)| not(C)| and(B,C)| nand(B,C)]`. This adds support for `v4i32, v2i64, v16i8, v8i16` operand types for the following patterns. List of xxeval equivalent ternary operations added and the corresponding imm value required: ``` ternary(A, and(B,C), nor(B,C)) 129 ternary(A, B, nor(B,C)) 131 ternary(A, C, nor(B,C)) 133 ternary(A, xor(B,C), nor(B,C)) 134 ternary(A, not(C), nor(B,C)) 138 ternary(A, not(B), nor(B,C)) 140 ternary(A, nand(B,C), nor(B,C)) 142 ternary(A, or(B,C), eqv(B,C)) 151 ternary(A, nor(B,C), eqv(B,C)) 152 ternary(A, not(C), eqv(B,C)) 154 ternary(A, nand(B,C), eqv(B,C)) 158 ternary(A, and(B,C), not(C)) 161 ternary(A, B, not(C)) 163 ternary(A, xor(B,C), not(C)) 166 ternary(A, or(B,C), not(C)) 167 ternary(A, not(B), not(C)) 172 ternary(A, nand(B,C), not(C)) 174 ternary(A, and(B,C), not(B)) 193 ternary(A, xor(B,C), not(B)) 198 ternary(A, or(B,C), not(B)) 199 ternary(A, nand(B,C), not(B)) 206 ternary(A, B, nand(B,C)) 227 ternary(A, C, nand(B,C)) 229 ternary(A, xor(B,C), nand(B,C)) 230 ternary(A, or(B,C), nand(B,C)) 231 ternary(A, eqv(B,C), nand(B,C)) 233 ``` eg. `xxeval XT, XA, XB, XC, 129` performs the ternary operation: `XA ? and(XB, XC) : nor(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)) - [[PowerPC] Exploit xxeval instruction for operations of the form ternary(A,X, XOR(B,C)) and ternary(A,X, OR(B,C))](#157909 (comment)) Co-authored-by: Tony Varghese <[email protected]>
1 parent 60ee515 commit d83fe12

File tree

6 files changed

+293
-291
lines changed

6 files changed

+293
-291
lines changed

llvm/lib/Target/PowerPC/PPCInstrP10.td

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,190 @@ multiclass XXEvalTernarySelectOr<ValueType Vt> {
24042404
126>;
24052405
}
24062406

2407+
// =============================================================================
2408+
// XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectNor
2409+
// This class matches the equivalent Ternary Operation: A ? f(B,C) : NOR(B,C)
2410+
// and emit the corresponding xxeval instruction with the imm value.
2411+
//
2412+
// The patterns implement xxeval vector select operations where:
2413+
// - A is the selector vector
2414+
// - f(B,C) is the "true" case op in set {B, C, AND(B,C), XOR(B,C), NOT(C),
2415+
// NOT(B), NAND(B,C)}
2416+
// - C is the "false" case op NOR(B,C)
2417+
// =============================================================================
2418+
multiclass XXEvalTernarySelectNor<ValueType Vt>{
2419+
// Pattern: (A ? AND(B,C) : NOR(B,C)) XXEVAL immediate value: 129
2420+
def : XXEvalPattern<
2421+
Vt, (vselect Vt:$vA, (VAnd Vt:$vB, Vt:$vC), (VNor Vt:$vB, Vt:$vC)),
2422+
129>;
2423+
2424+
// Pattern: (A ? B : NOR(B,C)) XXEVAL immediate value: 131
2425+
def : XXEvalPattern<Vt, (vselect Vt:$vA, Vt:$vB, (VNor Vt:$vB, Vt:$vC)),131>;
2426+
2427+
// Pattern: (A ? C : NOR(B,C)) XXEVAL immediate value: 133
2428+
def : XXEvalPattern<
2429+
Vt, (vselect Vt:$vA, Vt:$vC, (VNor Vt:$vB, Vt:$vC)),
2430+
133>;
2431+
2432+
// Pattern: (A ? XOR(B,C) : NOR(B,C)) XXEVAL immediate value: 134
2433+
def : XXEvalPattern<
2434+
Vt, (vselect Vt:$vA, (VXor Vt:$vB, Vt:$vC), (VNor Vt:$vB, Vt:$vC)),
2435+
134>;
2436+
2437+
// Pattern: (A ? NOT(C) : NOR(B,C)) XXEVAL immediate value: 138
2438+
def : XXEvalPattern<
2439+
Vt, (vselect Vt:$vA, (VNot Vt:$vC), (VNor Vt:$vB, Vt:$vC)),
2440+
138>;
2441+
2442+
// Pattern: (A ? NOT(B) : NOR(B,C)) XXEVAL immediate value: 140
2443+
def : XXEvalPattern<
2444+
Vt, (vselect Vt:$vA, (VNot Vt:$vB), (VNor Vt:$vB, Vt:$vC)),
2445+
140>;
2446+
2447+
// Pattern: (A ? NAND(B,C) : NOR(B,C)) XXEVAL immediate value: 142
2448+
def : XXEvalPattern<
2449+
Vt, (vselect Vt:$vA, (VNand Vt:$vB, Vt:$vC), (VNor Vt:$vB, Vt:$vC)),
2450+
142>;
2451+
}
2452+
2453+
// =============================================================================
2454+
// XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectEqv
2455+
// This class matches the equivalent Ternary Operation: A ? f(B,C) : EQV(B,C)
2456+
// and emit the corresponding xxeval instruction with the imm value.
2457+
//
2458+
// The patterns implement xxeval vector select operations where:
2459+
// - A is the selector vector
2460+
// - f(B,C) is the "true" case op in set {OR(B,C), NOR(B,C), NAND(B,C), NOT(B),
2461+
// NOT(C)}
2462+
// - C is the "false" case op EQV(B,C)
2463+
// =============================================================================
2464+
multiclass XXEvalTernarySelectEqv<ValueType Vt>{
2465+
// Pattern: (A ? OR(B,C) : EQV(B,C)) XXEVAL immediate value: 151
2466+
def : XXEvalPattern<
2467+
Vt, (vselect Vt:$vA, (VOr Vt:$vB, Vt:$vC), (VEqv Vt:$vB, Vt:$vC)),
2468+
151>;
2469+
2470+
// Pattern: (A ? NOR(B,C) : EQV(B,C)) XXEVAL immediate value: 152
2471+
def : XXEvalPattern<
2472+
Vt, (vselect Vt:$vA, (VNor Vt:$vB, Vt:$vC), (VEqv Vt:$vB, Vt:$vC)),
2473+
152>;
2474+
2475+
// Pattern: (A ? NOT(C) : EQV(B,C)) XXEVAL immediate value: 154
2476+
def : XXEvalPattern<
2477+
Vt, (vselect Vt:$vA, (VNot Vt:$vC), (VEqv Vt:$vB, Vt:$vC)),
2478+
154>;
2479+
2480+
// Pattern: (A ? NAND(B,C) : EQV(B,C)) XXEVAL immediate value: 158
2481+
def : XXEvalPattern<
2482+
Vt, (vselect Vt:$vA, (VNand Vt:$vB, Vt:$vC), (VEqv Vt:$vB, Vt:$vC)),
2483+
158>;
2484+
}
2485+
2486+
// =============================================================================
2487+
// XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectNotC
2488+
// This class matches the equivalent Ternary Operation: A ? f(B,C) : NOT(C)
2489+
// and emit the corresponding xxeval instruction with the imm value.
2490+
//
2491+
// The patterns implement xxeval vector select operations where:
2492+
// - A is the selector vector
2493+
// - f(B,C) is the "true" case op in set {AND(B,C), OR(B,C), XOR(B,C), NAND(B,C),
2494+
// B, NOT(B)}
2495+
// - C is the "false" case op NOT(C)
2496+
// =============================================================================
2497+
multiclass XXEvalTernarySelectNotC<ValueType Vt>{
2498+
// Pattern: (A ? AND(B,C) : NOT(C)) XXEVAL immediate value: 161
2499+
def : XXEvalPattern<
2500+
Vt, (vselect Vt:$vA, (VAnd Vt:$vB, Vt:$vC), (VNot Vt:$vC)), 161>;
2501+
2502+
// Pattern: (A ? B : NOT(C)) XXEVAL immediate value: 163
2503+
def : XXEvalPattern<Vt, (vselect Vt:$vA, Vt:$vB, (VNot Vt:$vC)), 163>;
2504+
2505+
// Pattern: (A ? XOR(B,C) : NOT(C)) XXEVAL immediate value: 166
2506+
def : XXEvalPattern<
2507+
Vt, (vselect Vt:$vA, (VXor Vt:$vB, Vt:$vC), (VNot Vt:$vC)), 166>;
2508+
2509+
// Pattern: (A ? OR(B,C) : NOT(C)) XXEVAL immediate value: 167
2510+
def : XXEvalPattern<
2511+
Vt, (vselect Vt:$vA, (VOr Vt:$vB, Vt:$vC), (VNot Vt:$vC)), 167>;
2512+
2513+
// Pattern: (A ? NOT(B) : NOT(C)) XXEVAL immediate value: 172
2514+
def : XXEvalPattern<Vt, (vselect Vt:$vA, (VNot Vt:$vB), (VNot Vt:$vC)), 172>;
2515+
2516+
// Pattern: (A ? NAND(B,C) : NOT(C)) XXEVAL immediate value: 174
2517+
def : XXEvalPattern<
2518+
Vt, (vselect Vt:$vA, (VNand Vt:$vB, Vt:$vC), (VNot Vt:$vC)), 174>;
2519+
}
2520+
2521+
// =============================================================================
2522+
// XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectNotB
2523+
// This class matches the equivalent Ternary Operation: A ? f(B,C) : NOT(B)
2524+
// and emit the corresponding xxeval instruction with the imm value.
2525+
//
2526+
// The patterns implement xxeval vector select operations where:
2527+
// - A is the selector vector
2528+
// - f(B,C) is the "true" case op in set {AND(B,C), OR(B,C), XOR(B,C), NAND(B,C),
2529+
// C, NOT(B)}
2530+
// - C is the "false" case op NOT(B)
2531+
// =============================================================================
2532+
multiclass XXEvalTernarySelectNotB<ValueType Vt>{
2533+
// Pattern: (A ? AND(B,C) : NOT(B)) XXEVAL immediate value: 193
2534+
def : XXEvalPattern<
2535+
Vt, (vselect Vt:$vA, (VAnd Vt:$vB, Vt:$vC), (VNot Vt:$vB)), 193>;
2536+
2537+
// Pattern: (A ? C : NOT(B)) XXEVAL immediate value: 197
2538+
def : XXEvalPattern<Vt, (vselect Vt:$vA, Vt:$vC, (VNot Vt:$vB)), 197>;
2539+
2540+
// Pattern: (A ? XOR(B,C) : NOT(B)) XXEVAL immediate value: 198
2541+
def : XXEvalPattern<
2542+
Vt, (vselect Vt:$vA, (VXor Vt:$vB, Vt:$vC), (VNot Vt:$vB)), 198>;
2543+
2544+
// Pattern: (A ? OR(B,C) : NOT(B)) XXEVAL immediate value: 199
2545+
def : XXEvalPattern<
2546+
Vt, (vselect Vt:$vA, (VOr Vt:$vB, Vt:$vC), (VNot Vt:$vB)), 199>;
2547+
2548+
// Pattern: (A ? NOT(C) : NOT(B)) XXEVAL immediate value: 202
2549+
def : XXEvalPattern<Vt, (vselect Vt:$vA, (VNot Vt:$vC), (VNot Vt:$vB)), 202>;
2550+
2551+
// Pattern: (A ? NAND(B,C) : NOT(B)) XXEVAL immediate value: 206
2552+
def : XXEvalPattern<
2553+
Vt, (vselect Vt:$vA, (VNand Vt:$vB, Vt:$vC), (VNot Vt:$vB)), 206>;
2554+
}
2555+
2556+
// =============================================================================
2557+
// XXEVAL Ternary Pattern Multiclass: XXEvalTernarySelectNand
2558+
// This class matches the equivalent Ternary Operation: A ? f(B,C) : NAND(B,C)
2559+
// and emit the corresponding xxeval instruction with the imm value.
2560+
//
2561+
// The patterns implement xxeval vector select operations where:
2562+
// - A is the selector vector
2563+
// - f(B,C) is the "true" case op in set {B, C, XOR(B,C), OR(B,C), EQV(B,C)}
2564+
// - C is the "false" case op NAND(B,C)
2565+
// =============================================================================
2566+
multiclass XXEvalTernarySelectNand<ValueType Vt>{
2567+
// Pattern: (A ? B : NAND(B,C)) XXEVAL immediate value: 227
2568+
def : XXEvalPattern<
2569+
Vt, (vselect Vt:$vA, Vt:$vB, (VNand Vt:$vB, Vt:$vC)), 227>;
2570+
2571+
// Pattern: (A ? C : NAND(B,C)) XXEVAL immediate value: 229
2572+
def : XXEvalPattern<
2573+
Vt, (vselect Vt:$vA, Vt:$vC, (VNand Vt:$vB, Vt:$vC)), 229>;
2574+
2575+
// Pattern: (A ? XOR(B,C) : NAND(B,C)) XXEVAL immediate value: 230
2576+
def : XXEvalPattern<
2577+
Vt, (vselect Vt:$vA, (VXor Vt:$vB, Vt:$vC), (VNand Vt:$vB, Vt:$vC)),
2578+
230>;
2579+
2580+
// Pattern: (A ? OR(B,C) : NAND(B,C)) XXEVAL immediate value: 231
2581+
def : XXEvalPattern<
2582+
Vt, (vselect Vt:$vA, (VOr Vt:$vB, Vt:$vC), (VNand Vt:$vB, Vt:$vC)),
2583+
231>;
2584+
2585+
// Pattern: (A ? EQV(B,C) : NAND(B,C)) XXEVAL immediate value: 233
2586+
def : XXEvalPattern<
2587+
Vt, (vselect Vt:$vA, (VEqv Vt:$vB, Vt:$vC), (VNand Vt:$vB, Vt:$vC)),
2588+
233>;
2589+
}
2590+
24072591
let Predicates = [PrefixInstrs, HasP10Vector] in {
24082592
let AddedComplexity = 400 in {
24092593
def : Pat<(v4i32 (build_vector i32immNonAllOneNonZero:$A,
@@ -2519,6 +2703,11 @@ let Predicates = [PrefixInstrs, HasP10Vector] in {
25192703
defm : XXEvalTernarySelectC<Ty>;
25202704
defm : XXEvalTernarySelectXor<Ty>;
25212705
defm : XXEvalTernarySelectOr<Ty>;
2706+
defm : XXEvalTernarySelectNor<Ty>;
2707+
defm : XXEvalTernarySelectEqv<Ty>;
2708+
defm : XXEvalTernarySelectNotC<Ty>;
2709+
defm : XXEvalTernarySelectNotB<Ty>;
2710+
defm : XXEvalTernarySelectNand<Ty>;
25222711
}
25232712

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

0 commit comments

Comments
 (0)