Skip to content

Commit 95fadc5

Browse files
committed
[X86] Changes made for code review comments
1 parent e94fc17 commit 95fadc5

File tree

4 files changed

+46
-42
lines changed

4 files changed

+46
-42
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23637,43 +23637,47 @@ static SDValue EmitTest(SDValue Op, X86::CondCode X86CC, const SDLoc &dl,
2363723637
// If optimising for size and can guarantee the shift amt is never zero
2363823638
// the test.
2363923639
bool OptForSize = DAG.getMachineFunction().getFunction().hasOptSize();
23640-
if (OptForSize && DAG.isKnownNeverZero(Amt)) {
23641-
SDLoc DL(ArithOp);
2364223640

23643-
// CopyToReg(CL, Amt)
23644-
SDValue Chain = DAG.getEntryNode();
23645-
SDValue Glue;
23641+
if (!OptForSize)
23642+
break;
2364623643

23647-
Chain = DAG.getCopyToReg(Chain, DL, X86::CL, Amt, Glue);
23648-
Glue = Chain.getValue(1);
23644+
if (!DAG.isKnownNeverZero(Amt))
23645+
break;
2364923646

23650-
// Select Opcode
23651-
unsigned X86Opcode;
23652-
switch (ArithOp.getOpcode()) {
23653-
case ISD::SHL:
23654-
X86Opcode = X86ISD::SHL;
23655-
break;
23656-
case ISD::SRL:
23657-
X86Opcode = X86ISD::SRL;
23658-
break;
23659-
case ISD::SRA:
23660-
X86Opcode = X86ISD::SRA;
23661-
break;
23662-
default:
23663-
llvm_unreachable("Unexpected shift opcode");
23664-
}
23647+
SDLoc DL(ArithOp);
2366523648

23666-
// Create Node [ValueToShift, Glue]
23667-
SDVTList VTs = DAG.getVTList(ArithOp.getValueType(), MVT::i32);
23668-
SDValue Ops[] = {ArithOp.getOperand(0), Glue};
23649+
// CopyToReg(CL, Amt)
23650+
SDValue Chain = DAG.getEntryNode();
23651+
SDValue Glue;
2366923652

23670-
SDValue NewNode = DAG.getNode(X86Opcode, DL, VTs, Ops);
23653+
Chain = DAG.getCopyToReg(Chain, DL, X86::CL, Amt, Glue);
23654+
Glue = Chain.getValue(1);
2367123655

23672-
// Replace and Return
23673-
DAG.ReplaceAllUsesOfValueWith(ArithOp, NewNode.getValue(0));
23674-
return NewNode.getValue(1);
23656+
// Select Opcode
23657+
unsigned X86Opcode;
23658+
switch (ArithOp.getOpcode()) {
23659+
case ISD::SHL:
23660+
X86Opcode = X86ISD::SHL;
23661+
break;
23662+
case ISD::SRL:
23663+
X86Opcode = X86ISD::SRL;
23664+
break;
23665+
case ISD::SRA:
23666+
X86Opcode = X86ISD::SRA;
23667+
break;
23668+
default:
23669+
llvm_unreachable("Unexpected shift opcode");
2367523670
}
23676-
break;
23671+
23672+
// Create Node [ValueToShift, Glue]
23673+
SDVTList VTs = DAG.getVTList(ArithOp.getValueType(), MVT::i32);
23674+
SDValue Ops[] = {ArithOp.getOperand(0), Glue};
23675+
23676+
SDValue NewNode = DAG.getNode(X86Opcode, DL, VTs, Ops);
23677+
23678+
// Replace and Return
23679+
DAG.ReplaceAllUsesOfValueWith(ArithOp, NewNode.getValue(0));
23680+
return NewNode.getValue(1);
2367723681
}
2367823682
default:
2367923683
break;

llvm/lib/Target/X86/X86ISelLowering.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ namespace llvm {
425425
OR,
426426
XOR,
427427
AND,
428+
SHL,
429+
SRL,
430+
SRA,
428431

429432
// Bit field extract.
430433
BEXTR,
@@ -996,9 +999,6 @@ namespace llvm {
996999
CLOAD,
9971000
CSTORE,
9981001
LAST_MEMORY_OPCODE = CSTORE,
999-
SHL,
1000-
SRL,
1001-
SRA,
10021002
};
10031003
} // end namespace X86ISD
10041004

llvm/lib/Target/X86/X86InstrFragments.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,15 @@ def X86xor_flag : SDNode<"X86ISD::XOR", SDTBinaryArithWithFlags,
276276
def X86and_flag : SDNode<"X86ISD::AND", SDTBinaryArithWithFlags,
277277
[SDNPCommutative]>;
278278

279+
def SDTX86ShiftWithFlags : SDTypeProfile<2, 1, [
280+
SDTCisSameAs<0, 2>,
281+
SDTCisVT<1, i32>,
282+
]>;
283+
284+
def X86shl : SDNode<"X86ISD::SHL", SDTX86ShiftWithFlags, [SDNPInGlue]>;
285+
def X86srl : SDNode<"X86ISD::SRL", SDTX86ShiftWithFlags, [SDNPInGlue]>;
286+
def X86sra : SDNode<"X86ISD::SRA", SDTX86ShiftWithFlags, [SDNPInGlue]>;
287+
279288
def X86lock_add : SDNode<"X86ISD::LADD", SDTLockBinaryArithWithFlags,
280289
[SDNPHasChain, SDNPMayStore, SDNPMayLoad,
281290
SDNPMemOperand]>;

llvm/lib/Target/X86/X86InstrShiftRotate.td

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -690,15 +690,6 @@ let Predicates = [HasBMI2, HasEGPR] in {
690690
defm SHLX : ShiftX_Pats<shl, "_EVEX">;
691691
}
692692

693-
def SDTX86ShiftWithFlags : SDTypeProfile<2, 1, [
694-
SDTCisSameAs<0, 2>,
695-
SDTCisVT<1, i32>,
696-
]>;
697-
698-
def X86shl : SDNode<"X86ISD::SHL", SDTX86ShiftWithFlags, [SDNPInGlue]>;
699-
def X86srl : SDNode<"X86ISD::SRL", SDTX86ShiftWithFlags, [SDNPInGlue]>;
700-
def X86sra : SDNode<"X86ISD::SRA", SDTX86ShiftWithFlags, [SDNPInGlue]>;
701-
702693
let Predicates = [NoNDD] in {
703694
// SHL
704695
def : Pat<(X86shl GR8:$src1), (SHL8rCL GR8:$src1)>;

0 commit comments

Comments
 (0)