[llvm] r372065 - [X86] Enable commuting of EVEX VCMP for all immediate values during isel.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 16 21:40:58 PDT 2019
Author: ctopper
Date: Mon Sep 16 21:40:58 2019
New Revision: 372065
URL: http://llvm.org/viewvc/llvm-project?rev=372065&view=rev
Log:
[X86] Enable commuting of EVEX VCMP for all immediate values during isel.
Modified:
llvm/trunk/lib/Target/X86/X86InstrAVX512.td
llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
llvm/trunk/lib/Target/X86/X86InstrInfo.h
llvm/trunk/test/CodeGen/X86/avx512-mask-op.ll
llvm/trunk/test/CodeGen/X86/select-of-fp-constants.ll
Modified: llvm/trunk/lib/Target/X86/X86InstrAVX512.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrAVX512.td?rev=372065&r1=372064&r2=372065&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrAVX512.td (original)
+++ llvm/trunk/lib/Target/X86/X86InstrAVX512.td Mon Sep 16 21:40:58 2019
@@ -2462,6 +2462,11 @@ def X86cmpmSAE_su : PatFrag<(ops node:$s
return N->hasOneUse();
}]>;
+def X86cmpm_imm_commute : SDNodeXForm<imm, [{
+ uint8_t Imm = X86::getSwappedVCMPImm(N->getZExtValue() & 0x1f);
+ return getI8Imm(Imm, SDLoc(N));
+}]>;
+
multiclass avx512_vcmp_common<X86FoldableSchedWrite sched, X86VectorVTInfo _,
string Name> {
defm rri : AVX512_maskable_cmp<0xC2, MRMSrcReg, _,
@@ -2498,29 +2503,29 @@ multiclass avx512_vcmp_common<X86Foldabl
// Patterns for selecting with loads in other operand.
def : Pat<(X86cmpm (_.LdFrag addr:$src2), (_.VT _.RC:$src1),
- CommutableCMPCC:$cc),
+ imm:$cc),
(!cast<Instruction>(Name#_.ZSuffix#"rmi") _.RC:$src1, addr:$src2,
- imm:$cc)>;
+ (X86cmpm_imm_commute imm:$cc))>;
def : Pat<(and _.KRCWM:$mask, (X86cmpm_su (_.LdFrag addr:$src2),
(_.VT _.RC:$src1),
- CommutableCMPCC:$cc)),
+ imm:$cc)),
(!cast<Instruction>(Name#_.ZSuffix#"rmik") _.KRCWM:$mask,
_.RC:$src1, addr:$src2,
- imm:$cc)>;
+ (X86cmpm_imm_commute imm:$cc))>;
def : Pat<(X86cmpm (X86VBroadcast (_.ScalarLdFrag addr:$src2)),
- (_.VT _.RC:$src1), CommutableCMPCC:$cc),
+ (_.VT _.RC:$src1), imm:$cc),
(!cast<Instruction>(Name#_.ZSuffix#"rmbi") _.RC:$src1, addr:$src2,
- imm:$cc)>;
+ (X86cmpm_imm_commute imm:$cc))>;
def : Pat<(and _.KRCWM:$mask, (X86cmpm_su (X86VBroadcast
(_.ScalarLdFrag addr:$src2)),
(_.VT _.RC:$src1),
- CommutableCMPCC:$cc)),
+ imm:$cc)),
(!cast<Instruction>(Name#_.ZSuffix#"rmbik") _.KRCWM:$mask,
_.RC:$src1, addr:$src2,
- imm:$cc)>;
+ (X86cmpm_imm_commute imm:$cc))>;
}
multiclass avx512_vcmp_sae<X86FoldableSchedWrite sched, X86VectorVTInfo _> {
@@ -2556,12 +2561,12 @@ defm VCMPPS : avx512_vcmp<SchedWriteFCmp
// Patterns to select fp compares with load as first operand.
let Predicates = [HasAVX512] in {
def : Pat<(v1i1 (X86cmpms (loadf64 addr:$src2), FR64X:$src1,
- CommutableCMPCC:$cc)),
- (VCMPSDZrm FR64X:$src1, addr:$src2, imm:$cc)>;
+ imm:$cc)),
+ (VCMPSDZrm FR64X:$src1, addr:$src2, (X86cmpm_imm_commute imm:$cc))>;
def : Pat<(v1i1 (X86cmpms (loadf32 addr:$src2), FR32X:$src1,
- CommutableCMPCC:$cc)),
- (VCMPSSZrm FR32X:$src1, addr:$src2, imm:$cc)>;
+ imm:$cc)),
+ (VCMPSSZrm FR32X:$src1, addr:$src2, (X86cmpm_imm_commute imm:$cc))>;
}
// ----------------------------------------------------------------
Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=372065&r1=372064&r2=372065&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Mon Sep 16 21:40:58 2019
@@ -2270,7 +2270,7 @@ unsigned X86::getVPCMPImmForCond(ISD::Co
}
}
-/// Get the VPCMP immediate if the opcodes are swapped.
+/// Get the VPCMP immediate if the operands are swapped.
unsigned X86::getSwappedVPCMPImm(unsigned Imm) {
switch (Imm) {
default: llvm_unreachable("Unreachable!");
@@ -2288,7 +2288,7 @@ unsigned X86::getSwappedVPCMPImm(unsigne
return Imm;
}
-/// Get the VPCOM immediate if the opcodes are swapped.
+/// Get the VPCOM immediate if the operands are swapped.
unsigned X86::getSwappedVPCOMImm(unsigned Imm) {
switch (Imm) {
default: llvm_unreachable("Unreachable!");
@@ -2303,6 +2303,23 @@ unsigned X86::getSwappedVPCOMImm(unsigne
break;
}
+ return Imm;
+}
+
+/// Get the VCMP immediate if the operands are swapped.
+unsigned X86::getSwappedVCMPImm(unsigned Imm) {
+ // Only need the lower 2 bits to distinquish.
+ switch (Imm & 0x3) {
+ default: llvm_unreachable("Unreachable!");
+ case 0x00: case 0x03:
+ // EQ/NE/TRUE/FALSE/ORD/UNORD don't change immediate when commuted.
+ break;
+ case 0x01: case 0x02:
+ // Need to toggle bits 3:0. Bit 4 stays the same.
+ Imm ^= 0xf;
+ break;
+ }
+
return Imm;
}
Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.h?rev=372065&r1=372064&r2=372065&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.h Mon Sep 16 21:40:58 2019
@@ -67,6 +67,9 @@ unsigned getSwappedVPCMPImm(unsigned Imm
/// Get the VPCOM immediate if the opcodes are swapped.
unsigned getSwappedVPCOMImm(unsigned Imm);
+/// Get the VCMP immediate if the opcodes are swapped.
+unsigned getSwappedVCMPImm(unsigned Imm);
+
} // namespace X86
/// isGlobalStubReference - Return true if the specified TargetFlag operand is
Modified: llvm/trunk/test/CodeGen/X86/avx512-mask-op.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/avx512-mask-op.ll?rev=372065&r1=372064&r2=372065&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/avx512-mask-op.ll (original)
+++ llvm/trunk/test/CodeGen/X86/avx512-mask-op.ll Mon Sep 16 21:40:58 2019
@@ -1968,8 +1968,7 @@ define <64 x i8> @test_build_vec_v64i1(<
define void @ktest_1(<8 x double> %in, double * %base) {
; KNL-LABEL: ktest_1:
; KNL: ## %bb.0:
-; KNL-NEXT: vmovupd (%rdi), %zmm1
-; KNL-NEXT: vcmpltpd %zmm0, %zmm1, %k1
+; KNL-NEXT: vcmpgtpd (%rdi), %zmm0, %k1
; KNL-NEXT: vmovupd 8(%rdi), %zmm1 {%k1} {z}
; KNL-NEXT: vcmpltpd %zmm1, %zmm0, %k0 {%k1}
; KNL-NEXT: kmovw %k0, %eax
@@ -1986,8 +1985,7 @@ define void @ktest_1(<8 x double> %in, d
;
; SKX-LABEL: ktest_1:
; SKX: ## %bb.0:
-; SKX-NEXT: vmovupd (%rdi), %zmm1
-; SKX-NEXT: vcmpltpd %zmm0, %zmm1, %k1
+; SKX-NEXT: vcmpgtpd (%rdi), %zmm0, %k1
; SKX-NEXT: vmovupd 8(%rdi), %zmm1 {%k1} {z}
; SKX-NEXT: vcmpltpd %zmm1, %zmm0, %k0 {%k1}
; SKX-NEXT: kortestb %k0, %k0
@@ -2003,8 +2001,7 @@ define void @ktest_1(<8 x double> %in, d
;
; AVX512BW-LABEL: ktest_1:
; AVX512BW: ## %bb.0:
-; AVX512BW-NEXT: vmovupd (%rdi), %zmm1
-; AVX512BW-NEXT: vcmpltpd %zmm0, %zmm1, %k1
+; AVX512BW-NEXT: vcmpgtpd (%rdi), %zmm0, %k1
; AVX512BW-NEXT: vmovupd 8(%rdi), %zmm1 {%k1} {z}
; AVX512BW-NEXT: vcmpltpd %zmm1, %zmm0, %k0 {%k1}
; AVX512BW-NEXT: kmovd %k0, %eax
@@ -2021,8 +2018,7 @@ define void @ktest_1(<8 x double> %in, d
;
; AVX512DQ-LABEL: ktest_1:
; AVX512DQ: ## %bb.0:
-; AVX512DQ-NEXT: vmovupd (%rdi), %zmm1
-; AVX512DQ-NEXT: vcmpltpd %zmm0, %zmm1, %k1
+; AVX512DQ-NEXT: vcmpgtpd (%rdi), %zmm0, %k1
; AVX512DQ-NEXT: vmovupd 8(%rdi), %zmm1 {%k1} {z}
; AVX512DQ-NEXT: vcmpltpd %zmm1, %zmm0, %k0 {%k1}
; AVX512DQ-NEXT: kortestb %k0, %k0
@@ -2039,8 +2035,7 @@ define void @ktest_1(<8 x double> %in, d
; X86-LABEL: ktest_1:
; X86: ## %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
-; X86-NEXT: vmovupd (%eax), %zmm1
-; X86-NEXT: vcmpltpd %zmm0, %zmm1, %k1
+; X86-NEXT: vcmpgtpd (%eax), %zmm0, %k1
; X86-NEXT: vmovupd 8(%eax), %zmm1 {%k1} {z}
; X86-NEXT: vcmpltpd %zmm1, %zmm0, %k0 {%k1}
; X86-NEXT: kortestb %k0, %k0
@@ -2084,10 +2079,8 @@ define void @ktest_2(<32 x float> %in, f
;
; KNL-LABEL: ktest_2:
; KNL: ## %bb.0:
-; KNL-NEXT: vmovups (%rdi), %zmm2
-; KNL-NEXT: vmovups 64(%rdi), %zmm3
-; KNL-NEXT: vcmpltps %zmm1, %zmm3, %k1
-; KNL-NEXT: vcmpltps %zmm0, %zmm2, %k2
+; KNL-NEXT: vcmpgtps 64(%rdi), %zmm1, %k1
+; KNL-NEXT: vcmpgtps (%rdi), %zmm0, %k2
; KNL-NEXT: vmovups 4(%rdi), %zmm2 {%k2} {z}
; KNL-NEXT: vmovups 68(%rdi), %zmm3 {%k1} {z}
; KNL-NEXT: vcmpltps %zmm3, %zmm1, %k0
@@ -2112,10 +2105,8 @@ define void @ktest_2(<32 x float> %in, f
;
; SKX-LABEL: ktest_2:
; SKX: ## %bb.0:
-; SKX-NEXT: vmovups (%rdi), %zmm2
-; SKX-NEXT: vmovups 64(%rdi), %zmm3
-; SKX-NEXT: vcmpltps %zmm0, %zmm2, %k1
-; SKX-NEXT: vcmpltps %zmm1, %zmm3, %k2
+; SKX-NEXT: vcmpgtps (%rdi), %zmm0, %k1
+; SKX-NEXT: vcmpgtps 64(%rdi), %zmm1, %k2
; SKX-NEXT: kunpckwd %k1, %k2, %k0
; SKX-NEXT: vmovups 68(%rdi), %zmm2 {%k2} {z}
; SKX-NEXT: vmovups 4(%rdi), %zmm3 {%k1} {z}
@@ -2137,10 +2128,8 @@ define void @ktest_2(<32 x float> %in, f
;
; AVX512BW-LABEL: ktest_2:
; AVX512BW: ## %bb.0:
-; AVX512BW-NEXT: vmovups (%rdi), %zmm2
-; AVX512BW-NEXT: vmovups 64(%rdi), %zmm3
-; AVX512BW-NEXT: vcmpltps %zmm0, %zmm2, %k1
-; AVX512BW-NEXT: vcmpltps %zmm1, %zmm3, %k2
+; AVX512BW-NEXT: vcmpgtps (%rdi), %zmm0, %k1
+; AVX512BW-NEXT: vcmpgtps 64(%rdi), %zmm1, %k2
; AVX512BW-NEXT: kunpckwd %k1, %k2, %k0
; AVX512BW-NEXT: vmovups 68(%rdi), %zmm2 {%k2} {z}
; AVX512BW-NEXT: vmovups 4(%rdi), %zmm3 {%k1} {z}
@@ -2162,10 +2151,8 @@ define void @ktest_2(<32 x float> %in, f
;
; AVX512DQ-LABEL: ktest_2:
; AVX512DQ: ## %bb.0:
-; AVX512DQ-NEXT: vmovups (%rdi), %zmm2
-; AVX512DQ-NEXT: vmovups 64(%rdi), %zmm3
-; AVX512DQ-NEXT: vcmpltps %zmm1, %zmm3, %k1
-; AVX512DQ-NEXT: vcmpltps %zmm0, %zmm2, %k2
+; AVX512DQ-NEXT: vcmpgtps 64(%rdi), %zmm1, %k1
+; AVX512DQ-NEXT: vcmpgtps (%rdi), %zmm0, %k2
; AVX512DQ-NEXT: vmovups 4(%rdi), %zmm2 {%k2} {z}
; AVX512DQ-NEXT: vmovups 68(%rdi), %zmm3 {%k1} {z}
; AVX512DQ-NEXT: vcmpltps %zmm3, %zmm1, %k0
@@ -2191,10 +2178,8 @@ define void @ktest_2(<32 x float> %in, f
; X86-LABEL: ktest_2:
; X86: ## %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
-; X86-NEXT: vmovups (%eax), %zmm2
-; X86-NEXT: vmovups 64(%eax), %zmm3
-; X86-NEXT: vcmpltps %zmm0, %zmm2, %k1
-; X86-NEXT: vcmpltps %zmm1, %zmm3, %k2
+; X86-NEXT: vcmpgtps (%eax), %zmm0, %k1
+; X86-NEXT: vcmpgtps 64(%eax), %zmm1, %k2
; X86-NEXT: kunpckwd %k1, %k2, %k0
; X86-NEXT: vmovups 68(%eax), %zmm2 {%k2} {z}
; X86-NEXT: vmovups 4(%eax), %zmm3 {%k1} {z}
Modified: llvm/trunk/test/CodeGen/X86/select-of-fp-constants.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/select-of-fp-constants.ll?rev=372065&r1=372064&r2=372065&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/select-of-fp-constants.ll (original)
+++ llvm/trunk/test/CodeGen/X86/select-of-fp-constants.ll Mon Sep 16 21:40:58 2019
@@ -61,7 +61,7 @@ define float @fcmp_select_fp_constants(f
; X32_AVX512F-LABEL: fcmp_select_fp_constants:
; X32_AVX512F: # %bb.0:
; X32_AVX512F-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; X32_AVX512F-NEXT: vcmpneqss {{[0-9]+}}(%esp), %xmm0, %k0
+; X32_AVX512F-NEXT: vcmpneqss {{\.LCPI.*}}, %xmm0, %k0
; X32_AVX512F-NEXT: kmovw %k0, %eax
; X32_AVX512F-NEXT: flds {{\.LCPI.*}}(,%eax,4)
; X32_AVX512F-NEXT: retl
More information about the llvm-commits
mailing list