Skip to content

Commit f523e83

Browse files
committed
[x86] make helper function to create sbb with zero operands; NFC
As noted in D116804, we want to effectively invert that patch for CPUs (intel) that don't break the false dependency on sbb %eax, %eax So we will likely want to create that here in the X86DAGToDAGISel::Select() case for X86::SETCC_CARRY.
1 parent 8680d6d commit f523e83

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,38 @@ namespace {
446446
return getI8Imm(InsertIdx ? 0x02 : 0x30, DL);
447447
}
448448

449+
SDValue getSBBZero(SDNode *N) {
450+
SDLoc dl(N);
451+
MVT VT = N->getSimpleValueType(0);
452+
453+
// Create zero.
454+
SDVTList VTs = CurDAG->getVTList(MVT::i32, MVT::i32);
455+
SDValue Zero =
456+
SDValue(CurDAG->getMachineNode(X86::MOV32r0, dl, VTs, None), 0);
457+
if (VT == MVT::i64) {
458+
Zero = SDValue(
459+
CurDAG->getMachineNode(
460+
TargetOpcode::SUBREG_TO_REG, dl, MVT::i64,
461+
CurDAG->getTargetConstant(0, dl, MVT::i64), Zero,
462+
CurDAG->getTargetConstant(X86::sub_32bit, dl, MVT::i32)),
463+
0);
464+
}
465+
466+
// Copy flags to the EFLAGS register and glue it to next node.
467+
SDValue EFLAGS = CurDAG->getCopyToReg(
468+
CurDAG->getEntryNode(), dl, X86::EFLAGS, N->getOperand(2), SDValue());
469+
470+
// Create a 64-bit instruction if the result is 64-bits otherwise use the
471+
// 32-bit version.
472+
unsigned Opc = VT == MVT::i64 ? X86::SBB64rr : X86::SBB32rr;
473+
MVT SBBVT = VT == MVT::i64 ? MVT::i64 : MVT::i32;
474+
VTs = CurDAG->getVTList(SBBVT, MVT::i32);
475+
return SDValue(
476+
CurDAG->getMachineNode(Opc, dl, VTs,
477+
{Zero, Zero, EFLAGS, EFLAGS.getValue(1)}),
478+
0);
479+
}
480+
449481
// Helper to detect unneeded and instructions on shift amounts. Called
450482
// from PatFrags in tablegen.
451483
bool isUnneededShiftMask(SDNode *N, unsigned Width) const {
@@ -5798,42 +5830,15 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
57985830
case X86ISD::SBB: {
57995831
if (isNullConstant(Node->getOperand(0)) &&
58005832
isNullConstant(Node->getOperand(1))) {
5801-
MVT VT = Node->getSimpleValueType(0);
5802-
5803-
// Create zero.
5804-
SDVTList VTs = CurDAG->getVTList(MVT::i32, MVT::i32);
5805-
SDValue Zero =
5806-
SDValue(CurDAG->getMachineNode(X86::MOV32r0, dl, VTs, None), 0);
5807-
if (VT == MVT::i64) {
5808-
Zero = SDValue(
5809-
CurDAG->getMachineNode(
5810-
TargetOpcode::SUBREG_TO_REG, dl, MVT::i64,
5811-
CurDAG->getTargetConstant(0, dl, MVT::i64), Zero,
5812-
CurDAG->getTargetConstant(X86::sub_32bit, dl, MVT::i32)),
5813-
0);
5814-
}
5815-
5816-
// Copy flags to the EFLAGS register and glue it to next node.
5817-
SDValue EFLAGS =
5818-
CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, X86::EFLAGS,
5819-
Node->getOperand(2), SDValue());
5820-
5821-
// Create a 64-bit instruction if the result is 64-bits otherwise use the
5822-
// 32-bit version.
5823-
unsigned Opc = VT == MVT::i64 ? X86::SBB64rr : X86::SBB32rr;
5824-
MVT SBBVT = VT == MVT::i64 ? MVT::i64 : MVT::i32;
5825-
VTs = CurDAG->getVTList(SBBVT, MVT::i32);
5826-
SDValue Result =
5827-
SDValue(CurDAG->getMachineNode(Opc, dl, VTs, {Zero, Zero, EFLAGS,
5828-
EFLAGS.getValue(1)}),
5829-
0);
5833+
SDValue Result = getSBBZero(Node);
58305834

58315835
// Replace the flag use.
58325836
ReplaceUses(SDValue(Node, 1), Result.getValue(1));
58335837

58345838
// Replace the result use.
58355839
if (!SDValue(Node, 0).use_empty()) {
58365840
// For less than 32-bits we need to extract from the 32-bit node.
5841+
MVT VT = Node->getSimpleValueType(0);
58375842
if (VT == MVT::i8 || VT == MVT::i16) {
58385843
int SubIndex = VT == MVT::i16 ? X86::sub_16bit : X86::sub_8bit;
58395844
Result = CurDAG->getTargetExtractSubreg(SubIndex, dl, VT, Result);

0 commit comments

Comments
 (0)