AVX-512: Fixed a bug in emitting compare for MVT:i1 type.

Added a test.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215889 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Elena Demikhovsky 2014-08-18 11:59:06 +00:00
parent 9f92467a53
commit 9735ccb7ea
5 changed files with 44 additions and 12 deletions

View File

@ -2544,12 +2544,30 @@ SDNode *X86DAGToDAGISel::Select(SDNode *Node) {
SDValue N0 = Node->getOperand(0);
SDValue N1 = Node->getOperand(1);
if (N0.getOpcode() == ISD::TRUNCATE && N0.hasOneUse() &&
HasNoSignedComparisonUses(Node)) {
// Look for (X86cmp (truncate $op, i1), 0) and try to convert to a
// smaller encoding
if (Opcode == X86ISD::CMP && N0.getValueType() == MVT::i1 &&
X86::isZeroNode(N1)) {
SDValue Reg = N0.getOperand(0);
SDValue Imm = CurDAG->getTargetConstant(1, MVT::i8);
// Emit testb
if (Reg.getScalarValueSizeInBits() > 8)
Reg = CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl, MVT::i8, Reg);
// Emit a testb.
SDNode *NewNode = CurDAG->getMachineNode(X86::TEST8ri, dl, MVT::i32,
Reg, Imm);
ReplaceUses(SDValue(Node, 0), SDValue(NewNode, 0));
return nullptr;
}
N0 = N0.getOperand(0);
}
// Look for (X86cmp (and $op, $imm), 0) and see if we can convert it to
// use a smaller encoding.
if (N0.getOpcode() == ISD::TRUNCATE && N0.hasOneUse() &&
HasNoSignedComparisonUses(Node))
// Look past the truncate if CMP is the only use of it.
N0 = N0.getOperand(0);
// Look past the truncate if CMP is the only use of it.
if ((N0.getNode()->getOpcode() == ISD::AND ||
(N0.getResNo() == 0 && N0.getNode()->getOpcode() == X86ISD::AND)) &&
N0.getNode()->hasOneUse() &&

View File

@ -11917,12 +11917,9 @@ SDValue X86TargetLowering::LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const {
if (VT == MVT::i1) {
assert((InVT.isInteger() && (InVT.getSizeInBits() <= 64)) &&
"Invalid scalar TRUNCATE operation");
if (InVT == MVT::i32)
if (InVT.getSizeInBits() >= 32)
return SDValue();
if (InVT.getSizeInBits() == 64)
In = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::i32, In);
else if (InVT.getSizeInBits() < 32)
In = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, In);
In = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, In);
return DAG.getNode(ISD::TRUNCATE, DL, VT, In);
}
assert(VT.getVectorNumElements() == InVT.getVectorNumElements() &&

View File

@ -1198,6 +1198,10 @@ let Predicates = [HasBWI] in {
}
let Predicates = [HasAVX512] in {
def : Pat<(i1 (trunc (i64 GR64:$src))),
(COPY_TO_REGCLASS (KMOVWkr (AND32ri (EXTRACT_SUBREG $src, sub_32bit),
(i32 1))), VK1)>;
def : Pat<(i1 (trunc (i32 GR32:$src))),
(COPY_TO_REGCLASS (KMOVWkr (AND32ri $src, (i32 1))), VK1)>;

View File

@ -85,3 +85,17 @@ define i32 @test8(i32 %a1, i32 %a2, i32 %a3) {
%res = select i1 %tmp5, i32 1, i32 %a3
ret i32 %res
}
; CHECK-LABEL: test9
; CHECK: testb
; CHECK-NOT: kmov
; CHECK: ret
define i32 @test9(i64 %a) {
%b = and i64 %a, 1
%cmp10.i = icmp eq i64 %b, 0
br i1 %cmp10.i, label %A, label %B
A:
ret i32 6
B:
ret i32 7
}

View File

@ -135,9 +135,8 @@ define <16 x i16> @trunc_v16i32_to_v16i16(<16 x i32> %x) {
}
; CHECK-LABEL: trunc_i32_to_i1
; CHECK: andl
; CHECK: kmov
; CHECK: kortest
; CHECK: testb
; CHECK: setne
; CKECK: orl
; CHECK: ret
define i16 @trunc_i32_to_i1(i32 %a) {