9
9
def BITOP3_32 : ComplexPattern<i32, 4, "SelectBITOP3", [and, or, xor]>;
10
10
def BITOP3_16 : ComplexPattern<i16, 4, "SelectBITOP3", [and, or, xor]>;
11
11
12
+ // Matches PTRADD as a commutative operation. Patterns using this PatFrag must
13
+ // set GISelShouldIgnore = 1 as commuting the corresponding G_PTR_ADD is
14
+ // invalid.
15
+ def ptradd_commutative : PatFrags<(ops node:$src0, node:$src1),
16
+ [(ptradd node:$src0, node:$src1), (ptradd node:$src1, node:$src0)]>;
17
+
12
18
// Special case for v_div_fmas_{f32|f64}, since it seems to be the
13
19
// only VOP instruction that implicitly reads VCC.
14
20
let Asm64 = " $vdst, $src0_modifiers, $src1_modifiers, $src2_modifiers$clamp$omod" in {
@@ -554,13 +560,12 @@ let OtherPredicates = [isGFX10Plus, Has16BitInsts], True16Predicate = NotHasTrue
554
560
defm: Ternary_i16_Pats_gfx9<mul, add, V_MAD_U16_gfx9_e64>;
555
561
} // End OtherPredicates = [isGFX10Plus, Has16BitInsts], True16Predicate = NotHasTrue16BitInsts
556
562
557
- class ThreeOpFragSDAG<SDPatternOperator op1, SDPatternOperator op2, bit op1IsRight = 0 > : PatFrag<
563
+ class ThreeOpFragSDAG<SDPatternOperator op1, SDPatternOperator op2> : PatFrag<
558
564
(ops node:$x, node:$y, node:$z),
559
565
// When the inner operation is used multiple times, selecting 3-op
560
566
// instructions may still be beneficial -- if the other users can be
561
567
// combined similarly. Let's be conservative for now.
562
- !if(op1IsRight, (op2 node:$z, (HasOneUseBinOp<op1> node:$x, node:$y)),
563
- (op2 (HasOneUseBinOp<op1> node:$x, node:$y), node:$z)),
568
+ (op2 (HasOneUseBinOp<op1> node:$x, node:$y), node:$z),
564
569
[{
565
570
// Only use VALU ops when the result is divergent.
566
571
if (!N->isDivergent())
@@ -587,10 +592,7 @@ class ThreeOpFragSDAG<SDPatternOperator op1, SDPatternOperator op2, bit op1IsRig
587
592
let PredicateCodeUsesOperands = 1;
588
593
}
589
594
590
- // Matches (op2 (op1 x, y), z) if op1IsRight = 0 and
591
- // matches (op2 z, (op1, x, y)) if op1IsRight = 1.
592
- class ThreeOpFrag<SDPatternOperator op1, SDPatternOperator op2,
593
- bit op1IsRight = 0> : ThreeOpFragSDAG<op1, op2, op1IsRight> {
595
+ class ThreeOpFrag<SDPatternOperator op1, SDPatternOperator op2> : ThreeOpFragSDAG<op1, op2> {
594
596
// The divergence predicate is irrelevant in GlobalISel, as we have
595
597
// proper register bank checks. We just need to verify the constant
596
598
// bus restriction when all the sources are considered.
@@ -949,10 +951,11 @@ def : GCNPat<
949
951
>;
950
952
951
953
def : GCNPat <
952
- // (ptradd z, (shl x, y)) -> ((x << y) + z)
953
- (ThreeOpFrag<shl_0_to_4, ptradd, /*op1IsRight=*/1> i64:$src0, i32:$src1, i64:$src2),
954
- (V_LSHL_ADD_U64_e64 VSrc_b64:$src0, VSrc_b32:$src1, VSrc_b64:$src2)
955
- >;
954
+ // (ptradd z, (shl x, y)) or (ptradd (shl x, y), z) -> ((x << y) + z)
955
+ (ThreeOpFrag<shl_0_to_4, ptradd_commutative> i64:$src0, i32:$src1, i64:$src2),
956
+ (V_LSHL_ADD_U64_e64 VSrc_b64:$src0, VSrc_b32:$src1, VSrc_b64:$src2)> {
957
+ let GISelShouldIgnore = 1;
958
+ }
956
959
} // End SubtargetPredicate = HasLshlAddU64Inst
957
960
958
961
let SubtargetPredicate = HasAddMinMaxInsts in {
@@ -1030,14 +1033,16 @@ multiclass IMAD32_Pats <VOP3_Pseudo inst> {
1030
1033
1031
1034
// Handle cases where amdgpu-codegenprepare-mul24 made a mul24 instead of a normal mul.
1032
1035
// We need to separate this because otherwise OtherPredicates would be overriden.
1033
- class IMAD32_Mul24_Pats_Impl<VOP3_Pseudo inst, SDPatternOperator AddOp, bit mulIsRight = 0 > : GCNPat <
1034
- !if(mulIsRight, ( i64 (AddOp i64:$src2, (i64 (AMDGPUmul_u24 i32:$src0, i32:$src1)))),
1035
- (i64 (AddOp (i64 (AMDGPUmul_u24 i32: $src0, i32: $src1)), i64: $src2))),
1036
- (inst $src0, $src1, $src2, 0 /* clamp */) >;
1036
+ class IMAD32_Mul24_Pats_Impl<VOP3_Pseudo inst, SDPatternOperator AddOp> : GCNPat <
1037
+ ( i64 (AddOp (i64 (AMDGPUmul_u24 i32:$src0, i32:$src1)), i64:$src2 )),
1038
+ (inst $src0, $src1, $src2, 0 /* clamp */)
1039
+ >;
1037
1040
1038
1041
multiclass IMAD32_Mul24_Pats<VOP3_Pseudo inst> {
1039
1042
def : IMAD32_Mul24_Pats_Impl<inst, add>;
1040
- def : IMAD32_Mul24_Pats_Impl<inst, ptradd, /*mulIsRight=*/1>;
1043
+ def : IMAD32_Mul24_Pats_Impl<inst, ptradd_commutative> {
1044
+ let GISelShouldIgnore = 1;
1045
+ }
1041
1046
}
1042
1047
1043
1048
// exclude pre-GFX9 where it was slow
0 commit comments