[llvm] r325317 - [X86] Don't zero_extend cmov up to i64, stop at i32.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 22:52:43 PST 2018
Author: ctopper
Date: Thu Feb 15 22:52:43 2018
New Revision: 325317
URL: http://llvm.org/viewvc/llvm-project?rev=325317&view=rev
Log:
[X86] Don't zero_extend cmov up to i64, stop at i32.
Zero extend from i32 to i64 is free. So extend from i16 to i32, and then use a free zero extend to finish.
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/test/CodeGen/X86/cmov-promotion.ll
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=325317&r1=325316&r2=325317&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Thu Feb 15 22:52:43 2018
@@ -36028,7 +36028,7 @@ static SDValue getDivRem8(SDNode *N, Sel
// promotion).
static SDValue combineToExtendCMOV(SDNode *Extend, SelectionDAG &DAG) {
SDValue CMovN = Extend->getOperand(0);
- if (CMovN.getOpcode() != X86ISD::CMOV)
+ if (CMovN.getOpcode() != X86ISD::CMOV || !CMovN.hasOneUse())
return SDValue();
EVT TargetVT = Extend->getValueType(0);
@@ -36039,20 +36039,35 @@ static SDValue combineToExtendCMOV(SDNod
SDValue CMovOp0 = CMovN.getOperand(0);
SDValue CMovOp1 = CMovN.getOperand(1);
- bool DoPromoteCMOV =
- (VT == MVT::i16 && (TargetVT == MVT::i32 || TargetVT == MVT::i64)) &&
- CMovN.hasOneUse() &&
- (isa<ConstantSDNode>(CMovOp0.getNode()) &&
- isa<ConstantSDNode>(CMovOp1.getNode()));
+ if (!isa<ConstantSDNode>(CMovOp0.getNode()) ||
+ !isa<ConstantSDNode>(CMovOp0.getNode()))
+ return SDValue();
+
+ // Only extend to i32 or i64.
+ if (TargetVT != MVT::i32 && TargetVT != MVT::i64)
+ return SDValue();
- if (!DoPromoteCMOV)
+ // Only extend from i16.
+ if (VT != MVT::i16)
return SDValue();
- CMovOp0 = DAG.getNode(ExtendOpcode, DL, TargetVT, CMovOp0);
- CMovOp1 = DAG.getNode(ExtendOpcode, DL, TargetVT, CMovOp1);
+ // If this a zero extend to i64, we should only extend to i32 and use a free
+ // zero extend to finish.
+ EVT ExtendVT = TargetVT;
+ if (TargetVT == MVT::i64 && ExtendOpcode == ISD::ZERO_EXTEND)
+ ExtendVT = MVT::i32;
+
+ CMovOp0 = DAG.getNode(ExtendOpcode, DL, ExtendVT, CMovOp0);
+ CMovOp1 = DAG.getNode(ExtendOpcode, DL, ExtendVT, CMovOp1);
+
+ SDValue Res = DAG.getNode(X86ISD::CMOV, DL, ExtendVT, CMovOp0, CMovOp1,
+ CMovN.getOperand(2), CMovN.getOperand(3));
+
+ // Finish extending if needed.
+ if (ExtendVT != TargetVT)
+ Res = DAG.getNode(ISD::ZERO_EXTEND, DL, TargetVT, Res);
- return DAG.getNode(X86ISD::CMOV, DL, TargetVT, CMovOp0, CMovOp1,
- CMovN.getOperand(2), CMovN.getOperand(3));
+ return Res;
}
// Convert (vXiY *ext(vXi1 bitcast(iX))) to extend_in_reg(broadcast(iX)).
Modified: llvm/trunk/test/CodeGen/X86/cmov-promotion.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cmov-promotion.ll?rev=325317&r1=325316&r2=325317&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/cmov-promotion.ll (original)
+++ llvm/trunk/test/CodeGen/X86/cmov-promotion.ll Thu Feb 15 22:52:43 2018
@@ -115,7 +115,7 @@ define i64 @cmov_zpromotion_16_to_64(i1
; CMOV-NEXT: testb $1, %dil
; CMOV-NEXT: movl $12414, %ecx # imm = 0x307E
; CMOV-NEXT: movl $65535, %eax # imm = 0xFFFF
-; CMOV-NEXT: cmovneq %rcx, %rax
+; CMOV-NEXT: cmovnel %ecx, %eax
; CMOV-NEXT: retq
;
; NO_CMOV-LABEL: cmov_zpromotion_16_to_64:
More information about the llvm-commits
mailing list