diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-02-18 21:03:28 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-02-18 21:03:28 +0000 |
commit | 12c2093e1ee8cc814984fc10da0c36a90d12ac43 (patch) | |
tree | da770eda1b154231fb1a0a987b14285742478ab8 /llvm/lib/Target | |
parent | 079d5118911a493ea809f3b9b276529a548afe71 (diff) | |
download | bcm5719-llvm-12c2093e1ee8cc814984fc10da0c36a90d12ac43.tar.gz bcm5719-llvm-12c2093e1ee8cc814984fc10da0c36a90d12ac43.zip |
[x86] fold sext (xor Bool, -1) --> sub (zext Bool), 1
This is the same transform that is current used for:
select Bool, 0, -1
llvm-svn: 295568
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 57d937dd545..5522c7138b9 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -33436,6 +33436,16 @@ static SDValue combineSext(SDNode *N, SelectionDAG &DAG, return SDValue(); } + if (InVT == MVT::i1 && N0.getOpcode() == ISD::XOR && + isAllOnesConstant(N0.getOperand(1)) && N0.hasOneUse()) { + // Invert and sign-extend a boolean is the same as zero-extend and subtract + // 1 because 0 becomes -1 and 1 becomes 0. The subtract is efficiently + // lowered with an LEA or a DEC. This is the same as: select Bool, 0, -1. + // sext (xor Bool, -1) --> sub (zext Bool), 1 + SDValue Zext = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, N0.getOperand(0)); + return DAG.getNode(ISD::SUB, DL, VT, Zext, DAG.getConstant(1, DL, VT)); + } + if (SDValue V = combineToExtendVectorInReg(N, DAG, DCI, Subtarget)) return V; |