Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 0eec3b0

Browse files
committed
[DAG] early exit to improve readability and formatting of visitMemCmpCall(); NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296824 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 06a22af commit 0eec3b0

File tree

1 file changed

+53
-64
lines changed

1 file changed

+53
-64
lines changed

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 53 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6027,11 +6027,9 @@ bool SelectionDAGBuilder::visitMemCmpCall(const CallInst &I) {
60276027
}
60286028

60296029
const SelectionDAGTargetInfo &TSI = DAG.getSelectionDAGInfo();
6030-
std::pair<SDValue, SDValue> Res =
6031-
TSI.EmitTargetCodeForMemcmp(DAG, getCurSDLoc(), DAG.getRoot(),
6032-
getValue(LHS), getValue(RHS), getValue(Size),
6033-
MachinePointerInfo(LHS),
6034-
MachinePointerInfo(RHS));
6030+
std::pair<SDValue, SDValue> Res = TSI.EmitTargetCodeForMemcmp(
6031+
DAG, getCurSDLoc(), DAG.getRoot(), getValue(LHS), getValue(RHS),
6032+
getValue(Size), MachinePointerInfo(LHS), MachinePointerInfo(RHS));
60356033
if (Res.first.getNode()) {
60366034
processIntegerCallValue(I, Res.first, true);
60376035
PendingLoads.push_back(Res.second);
@@ -6040,70 +6038,61 @@ bool SelectionDAGBuilder::visitMemCmpCall(const CallInst &I) {
60406038

60416039
// memcmp(S1,S2,2) != 0 -> (*(short*)LHS != *(short*)RHS) != 0
60426040
// memcmp(S1,S2,4) != 0 -> (*(int*)LHS != *(int*)RHS) != 0
6043-
if (CSize && IsOnlyUsedInZeroEqualityComparison(&I)) {
6044-
bool ActuallyDoIt = true;
6045-
MVT LoadVT;
6046-
Type *LoadTy;
6047-
switch (CSize->getZExtValue()) {
6048-
default:
6049-
LoadVT = MVT::Other;
6050-
LoadTy = nullptr;
6051-
ActuallyDoIt = false;
6052-
break;
6053-
case 2:
6054-
LoadVT = MVT::i16;
6055-
LoadTy = Type::getInt16Ty(CSize->getContext());
6056-
break;
6057-
case 4:
6058-
LoadVT = MVT::i32;
6059-
LoadTy = Type::getInt32Ty(CSize->getContext());
6060-
break;
6061-
case 8:
6062-
LoadVT = MVT::i64;
6063-
LoadTy = Type::getInt64Ty(CSize->getContext());
6064-
break;
6065-
/*
6066-
case 16:
6067-
LoadVT = MVT::v4i32;
6068-
LoadTy = Type::getInt32Ty(CSize->getContext());
6069-
LoadTy = VectorType::get(LoadTy, 4);
6070-
break;
6071-
*/
6072-
}
6073-
6074-
// This turns into unaligned loads. We only do this if the target natively
6075-
// supports the MVT we'll be loading or if it is small enough (<= 4) that
6076-
// we'll only produce a small number of byte loads.
6041+
if (!CSize || !IsOnlyUsedInZeroEqualityComparison(&I))
6042+
return false;
60776043

6078-
// Require that we can find a legal MVT, and only do this if the target
6079-
// supports unaligned loads of that type. Expanding into byte loads would
6080-
// bloat the code.
6081-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6082-
if (ActuallyDoIt && CSize->getZExtValue() > 4) {
6083-
unsigned DstAS = LHS->getType()->getPointerAddressSpace();
6084-
unsigned SrcAS = RHS->getType()->getPointerAddressSpace();
6085-
// TODO: Handle 5 byte compare as 4-byte + 1 byte.
6086-
// TODO: Handle 8 byte compare on x86-32 as two 32-bit loads.
6087-
// TODO: Check alignment of src and dest ptrs.
6088-
if (!TLI.isTypeLegal(LoadVT) ||
6089-
!TLI.allowsMisalignedMemoryAccesses(LoadVT, SrcAS) ||
6090-
!TLI.allowsMisalignedMemoryAccesses(LoadVT, DstAS))
6091-
ActuallyDoIt = false;
6092-
}
6044+
MVT LoadVT;
6045+
Type *LoadTy;
6046+
switch (CSize->getZExtValue()) {
6047+
default:
6048+
return false;
6049+
case 2:
6050+
LoadVT = MVT::i16;
6051+
LoadTy = Type::getInt16Ty(CSize->getContext());
6052+
break;
6053+
case 4:
6054+
LoadVT = MVT::i32;
6055+
LoadTy = Type::getInt32Ty(CSize->getContext());
6056+
break;
6057+
case 8:
6058+
LoadVT = MVT::i64;
6059+
LoadTy = Type::getInt64Ty(CSize->getContext());
6060+
break;
6061+
/*
6062+
case 16:
6063+
LoadVT = MVT::v4i32;
6064+
LoadTy = Type::getInt32Ty(CSize->getContext());
6065+
LoadTy = VectorType::get(LoadTy, 4);
6066+
break;
6067+
*/
6068+
}
60936069

6094-
if (ActuallyDoIt) {
6095-
SDValue LHSVal = getMemCmpLoad(LHS, LoadVT, LoadTy, *this);
6096-
SDValue RHSVal = getMemCmpLoad(RHS, LoadVT, LoadTy, *this);
6070+
// This turns into unaligned loads. We only do this if the target natively
6071+
// supports the MVT we'll be loading or if it is small enough (<= 4) that
6072+
// we'll only produce a small number of byte loads.
60976073

6098-
SDValue Res = DAG.getSetCC(getCurSDLoc(), MVT::i1, LHSVal, RHSVal,
6099-
ISD::SETNE);
6100-
processIntegerCallValue(I, Res, false);
6101-
return true;
6102-
}
6074+
// Require that we can find a legal MVT, and only do this if the target
6075+
// supports unaligned loads of that type. Expanding into byte loads would
6076+
// bloat the code.
6077+
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6078+
if (CSize->getZExtValue() > 4) {
6079+
unsigned DstAS = LHS->getType()->getPointerAddressSpace();
6080+
unsigned SrcAS = RHS->getType()->getPointerAddressSpace();
6081+
// TODO: Handle 5 byte compare as 4-byte + 1 byte.
6082+
// TODO: Handle 8 byte compare on x86-32 as two 32-bit loads.
6083+
// TODO: Check alignment of src and dest ptrs.
6084+
if (!TLI.isTypeLegal(LoadVT) ||
6085+
!TLI.allowsMisalignedMemoryAccesses(LoadVT, SrcAS) ||
6086+
!TLI.allowsMisalignedMemoryAccesses(LoadVT, DstAS))
6087+
return false;
61036088
}
61046089

6105-
6106-
return false;
6090+
SDValue LHSVal = getMemCmpLoad(LHS, LoadVT, LoadTy, *this);
6091+
SDValue RHSVal = getMemCmpLoad(RHS, LoadVT, LoadTy, *this);
6092+
SDValue SetCC =
6093+
DAG.getSetCC(getCurSDLoc(), MVT::i1, LHSVal, RHSVal, ISD::SETNE);
6094+
processIntegerCallValue(I, SetCC, false);
6095+
return true;
61076096
}
61086097

61096098
/// See if we can lower a memchr call into an optimized form. If so, return

0 commit comments

Comments
 (0)