diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vadd-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vadd-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vadd-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vadd-vp.ll @@ -131,10 +131,8 @@ define <4 x i8> @vadd_vx_v4i8_commute(<4 x i8> %va, i8 %b, <4 x i1> %m, i32 zeroext %evl) { ; CHECK-LABEL: vadd_vx_v4i8_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e8, mf4, ta, mu -; CHECK-NEXT: vadd.vv v8, v9, v8, v0.t +; CHECK-NEXT: vadd.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement <4 x i8> undef, i8 %b, i32 0 %vb = shufflevector <4 x i8> %elt.head, <4 x i8> undef, <4 x i32> zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vand-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vand-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vand-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vand-vp.ll @@ -55,10 +55,8 @@ define <2 x i8> @vand_vx_v2i8_commute(<2 x i8> %va, i8 %b, <2 x i1> %m, i32 zeroext %evl) { ; CHECK-LABEL: vand_vx_v2i8_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetivli zero, 2, e8, mf8, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e8, mf8, ta, mu -; CHECK-NEXT: vand.vv v8, v9, v8, v0.t +; CHECK-NEXT: vand.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement <2 x i8> undef, i8 %b, i32 0 %vb = shufflevector <2 x i8> %elt.head, <2 x i8> undef, <2 x i32> zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfadd-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfadd-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfadd-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfadd-vp.ll @@ -255,10 +255,8 @@ define <2 x float> @vfadd_vf_v2f32_commute(<2 x float> %va, float %b, <2 x i1> %m, i32 zeroext %evl) { ; CHECK-LABEL: vfadd_vf_v2f32_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, mu -; CHECK-NEXT: vfmv.v.f v9, fa0 ; CHECK-NEXT: vsetvli zero, a0, e32, mf2, ta, mu -; CHECK-NEXT: vfadd.vv v8, v9, v8, v0.t +; CHECK-NEXT: vfadd.vf v8, v8, fa0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement <2 x float> undef, float %b, i32 0 %vb = shufflevector <2 x float> %elt.head, <2 x float> undef, <2 x i32> zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vmul-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vmul-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vmul-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vmul-vp.ll @@ -355,10 +355,8 @@ define <8 x i16> @vmul_vx_v8i16_commute(<8 x i16> %va, i16 %b, <8 x i1> %m, i32 zeroext %evl) { ; CHECK-LABEL: vmul_vx_v8i16_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetivli zero, 8, e16, m1, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e16, m1, ta, mu -; CHECK-NEXT: vmul.vv v8, v9, v8, v0.t +; CHECK-NEXT: vmul.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement <8 x i16> undef, i16 %b, i32 0 %vb = shufflevector <8 x i16> %elt.head, <8 x i16> undef, <8 x i32> zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vor-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vor-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vor-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vor-vp.ll @@ -131,10 +131,8 @@ define <4 x i8> @vor_vx_v4i8_commute(<4 x i8> %va, i8 %b, <4 x i1> %m, i32 zeroext %evl) { ; CHECK-LABEL: vor_vx_v4i8_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e8, mf4, ta, mu -; CHECK-NEXT: vor.vv v8, v9, v8, v0.t +; CHECK-NEXT: vor.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement <4 x i8> undef, i8 %b, i32 0 %vb = shufflevector <4 x i8> %elt.head, <4 x i8> undef, <4 x i32> zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vxor-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vxor-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vxor-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vxor-vp.ll @@ -55,10 +55,8 @@ define <2 x i8> @vxor_vx_v2i8_commute(<2 x i8> %va, i8 %b, <2 x i1> %m, i32 zeroext %evl) { ; CHECK-LABEL: vxor_vx_v2i8_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetivli zero, 2, e8, mf8, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e8, mf8, ta, mu -; CHECK-NEXT: vxor.vv v8, v9, v8, v0.t +; CHECK-NEXT: vxor.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement <2 x i8> undef, i8 %b, i32 0 %vb = shufflevector <2 x i8> %elt.head, <2 x i8> undef, <2 x i32> zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/vadd-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vadd-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vadd-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vadd-vp.ll @@ -57,10 +57,8 @@ define @vadd_vx_nxv1i8_commute( %va, i8 %b, %m, i32 zeroext %evl) { ; CHECK-LABEL: vadd_vx_nxv1i8_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetvli a2, zero, e8, mf8, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e8, mf8, ta, mu -; CHECK-NEXT: vadd.vv v8, v9, v8, v0.t +; CHECK-NEXT: vadd.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement undef, i8 %b, i32 0 %vb = shufflevector %elt.head, undef, zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/vand-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vand-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vand-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vand-vp.ll @@ -1045,10 +1045,8 @@ define @vand_vx_nxv32i16_commute( %va, i16 %b, %m, i32 zeroext %evl) { ; CHECK-LABEL: vand_vx_nxv32i16_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetvli a2, zero, e16, m8, ta, mu -; CHECK-NEXT: vmv.v.x v16, a0 ; CHECK-NEXT: vsetvli zero, a1, e16, m8, ta, mu -; CHECK-NEXT: vand.vv v8, v16, v8, v0.t +; CHECK-NEXT: vand.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement undef, i16 %b, i32 0 %vb = shufflevector %elt.head, undef, zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/vmul-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vmul-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vmul-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vmul-vp.ll @@ -957,10 +957,8 @@ define @vmul_vx_nxv16i32_commute( %va, i32 %b, %m, i32 zeroext %evl) { ; CHECK-LABEL: vmul_vx_nxv16i32_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetvli a2, zero, e32, m8, ta, mu -; CHECK-NEXT: vmv.v.x v16, a0 ; CHECK-NEXT: vsetvli zero, a1, e32, m8, ta, mu -; CHECK-NEXT: vmul.vv v8, v16, v8, v0.t +; CHECK-NEXT: vmul.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement undef, i32 %b, i32 0 %vb = shufflevector %elt.head, undef, zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/vor-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vor-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vor-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vor-vp.ll @@ -1121,10 +1121,8 @@ define @vor_vx_nxv2i32_commute( %va, i32 %b, %m, i32 zeroext %evl) { ; CHECK-LABEL: vor_vx_nxv2i32_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetvli a2, zero, e32, m1, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, mu -; CHECK-NEXT: vor.vv v8, v9, v8, v0.t +; CHECK-NEXT: vor.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement undef, i32 %b, i32 0 %vb = shufflevector %elt.head, undef, zeroinitializer diff --git a/llvm/test/CodeGen/RISCV/rvv/vxor-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vxor-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vxor-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vxor-vp.ll @@ -873,10 +873,8 @@ define @vxor_vx_nxv1i16_commute( %va, i16 %b, %m, i32 zeroext %evl) { ; CHECK-LABEL: vxor_vx_nxv1i16_commute: ; CHECK: # %bb.0: -; CHECK-NEXT: vsetvli a2, zero, e16, mf4, ta, mu -; CHECK-NEXT: vmv.v.x v9, a0 ; CHECK-NEXT: vsetvli zero, a1, e16, mf4, ta, mu -; CHECK-NEXT: vxor.vv v8, v9, v8, v0.t +; CHECK-NEXT: vxor.vx v8, v8, a0, v0.t ; CHECK-NEXT: ret %elt.head = insertelement undef, i16 %b, i32 0 %vb = shufflevector %elt.head, undef, zeroinitializer diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -4645,39 +4645,33 @@ // If this node is commutative, consider the commuted order. bool isCommIntrinsic = N->isCommutativeIntrinsic(CDP); if (NodeInfo.hasProperty(SDNPCommutative) || isCommIntrinsic) { - assert((N->getNumChildren()>=2 || isCommIntrinsic) && + assert(N->getNumChildren()>=2 && + (!isCommIntrinsic || N->getNumChildren()>=3) && "Commutative but doesn't have 2 children!"); - // Don't count children which are actually register references. - unsigned NC = 0; - for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) { + // Don't allow commuting children which are actually register references. + bool NoRegisters = true; + unsigned i = isCommIntrinsic ? 1 : 0; + unsigned e = isCommIntrinsic ? 3 : 2; + for (; i != e; ++i) { TreePatternNode *Child = N->getChild(i); if (Child->isLeaf()) if (DefInit *DI = dyn_cast(Child->getLeafValue())) { Record *RR = DI->getDef(); if (RR->isSubClassOf("Register")) - continue; + NoRegisters = false; } - NC++; } // Consider the commuted order. - if (isCommIntrinsic) { - // Commutative intrinsic. First operand is the intrinsic id, 2nd and 3rd - // operands are the commutative operands, and there might be more operands - // after those. - assert(NC >= 3 && - "Commutative intrinsic should have at least 3 children!"); - std::vector> Variants; - Variants.push_back(std::move(ChildVariants[0])); // Intrinsic id. - Variants.push_back(std::move(ChildVariants[2])); - Variants.push_back(std::move(ChildVariants[1])); - for (unsigned i = 3; i != NC; ++i) - Variants.push_back(std::move(ChildVariants[i])); - CombineChildVariants(N, Variants, OutVariants, CDP, DepVars); - } else if (NC == N->getNumChildren()) { + if (NoRegisters) { std::vector> Variants; - Variants.push_back(std::move(ChildVariants[1])); - Variants.push_back(std::move(ChildVariants[0])); - for (unsigned i = 2; i != NC; ++i) + unsigned i = 0; + if (isCommIntrinsic) + Variants.push_back(std::move(ChildVariants[i++])); // Intrinsic id. + Variants.push_back(std::move(ChildVariants[i+1])); + Variants.push_back(std::move(ChildVariants[i])); + i += 2; + // Remaining operands are not commuted. + for (; i != N->getNumChildren(); ++i) Variants.push_back(std::move(ChildVariants[i])); CombineChildVariants(N, Variants, OutVariants, CDP, DepVars); }