Skip to content

Commit dafd178

Browse files
committed
[InstCombine][NFC] Format code in foldCmpLoadFromIndexedGlobal
1 parent e13e95b commit dafd178

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
111111
LoadInst *LI, GetElementPtrInst *GEP, GlobalVariable *GV, CmpInst &ICI,
112112
ConstantInt *AndCst) {
113113
if (LI->isVolatile() || LI->getType() != GEP->getResultElementType() ||
114-
GV->getValueType() != GEP->getSourceElementType() ||
115-
!GV->isConstant() || !GV->hasDefinitiveInitializer())
114+
GV->getValueType() != GEP->getSourceElementType() || !GV->isConstant() ||
115+
!GV->hasDefinitiveInitializer())
116116
return nullptr;
117117

118118
Constant *Init = GV->getInitializer();
@@ -128,8 +128,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
128128
// the simple index into a single-dimensional array.
129129
//
130130
// Require: GEP GV, 0, i {{, constant indices}}
131-
if (GEP->getNumOperands() < 3 ||
132-
!isa<ConstantInt>(GEP->getOperand(1)) ||
131+
if (GEP->getNumOperands() < 3 || !isa<ConstantInt>(GEP->getOperand(1)) ||
133132
!cast<ConstantInt>(GEP->getOperand(1))->isZero() ||
134133
isa<Constant>(GEP->getOperand(2)))
135134
return nullptr;
@@ -142,15 +141,18 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
142141
Type *EltTy = Init->getType()->getArrayElementType();
143142
for (unsigned i = 3, e = GEP->getNumOperands(); i != e; ++i) {
144143
ConstantInt *Idx = dyn_cast<ConstantInt>(GEP->getOperand(i));
145-
if (!Idx) return nullptr; // Variable index.
144+
if (!Idx)
145+
return nullptr; // Variable index.
146146

147147
uint64_t IdxVal = Idx->getZExtValue();
148-
if ((unsigned)IdxVal != IdxVal) return nullptr; // Too large array index.
148+
if ((unsigned)IdxVal != IdxVal)
149+
return nullptr; // Too large array index.
149150

150151
if (StructType *STy = dyn_cast<StructType>(EltTy))
151152
EltTy = STy->getElementType(IdxVal);
152153
else if (ArrayType *ATy = dyn_cast<ArrayType>(EltTy)) {
153-
if (IdxVal >= ATy->getNumElements()) return nullptr;
154+
if (IdxVal >= ATy->getNumElements())
155+
return nullptr;
154156
EltTy = ATy->getElementType();
155157
} else {
156158
return nullptr; // Unknown type.
@@ -191,7 +193,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
191193
Constant *CompareRHS = cast<Constant>(ICI.getOperand(1));
192194
for (unsigned i = 0, e = ArrayElementCount; i != e; ++i) {
193195
Constant *Elt = Init->getAggregateElement(i);
194-
if (!Elt) return nullptr;
196+
if (!Elt)
197+
return nullptr;
195198

196199
// If this is indexing an array of structures, get the structure element.
197200
if (!LaterIndices.empty()) {
@@ -214,16 +217,17 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
214217
if (isa<UndefValue>(C)) {
215218
// Extend range state machines to cover this element in case there is an
216219
// undef in the middle of the range.
217-
if (TrueRangeEnd == (int)i-1)
220+
if (TrueRangeEnd == (int)i - 1)
218221
TrueRangeEnd = i;
219-
if (FalseRangeEnd == (int)i-1)
222+
if (FalseRangeEnd == (int)i - 1)
220223
FalseRangeEnd = i;
221224
continue;
222225
}
223226

224227
// If we can't compute the result for any of the elements, we have to give
225228
// up evaluating the entire conditional.
226-
if (!isa<ConstantInt>(C)) return nullptr;
229+
if (!isa<ConstantInt>(C))
230+
return nullptr;
227231

228232
// Otherwise, we know if the comparison is true or false for this element,
229233
// update our state machines.
@@ -233,7 +237,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
233237
if (IsTrueForElt) {
234238
// Update the TrueElement state machine.
235239
if (FirstTrueElement == Undefined)
236-
FirstTrueElement = TrueRangeEnd = i; // First true element.
240+
FirstTrueElement = TrueRangeEnd = i; // First true element.
237241
else {
238242
// Update double-compare state machine.
239243
if (SecondTrueElement == Undefined)
@@ -242,7 +246,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
242246
SecondTrueElement = Overdefined;
243247

244248
// Update range state machine.
245-
if (TrueRangeEnd == (int)i-1)
249+
if (TrueRangeEnd == (int)i - 1)
246250
TrueRangeEnd = i;
247251
else
248252
TrueRangeEnd = Overdefined;
@@ -259,7 +263,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
259263
SecondFalseElement = Overdefined;
260264

261265
// Update range state machine.
262-
if (FalseRangeEnd == (int)i-1)
266+
if (FalseRangeEnd == (int)i - 1)
263267
FalseRangeEnd = i;
264268
else
265269
FalseRangeEnd = Overdefined;
@@ -348,7 +352,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
348352

349353
// False for two elements -> 'i != 47 & i != 72'.
350354
Value *C1 = Builder.CreateICmpNE(Idx, FirstFalseIdx);
351-
Value *SecondFalseIdx = ConstantInt::get(Idx->getType(),SecondFalseElement);
355+
Value *SecondFalseIdx =
356+
ConstantInt::get(Idx->getType(), SecondFalseElement);
352357
Value *C2 = Builder.CreateICmpNE(Idx, SecondFalseIdx);
353358
return BinaryOperator::CreateAnd(C1, C2);
354359
}
@@ -365,8 +370,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
365370
Idx = Builder.CreateAdd(Idx, Offs);
366371
}
367372

368-
Value *End = ConstantInt::get(Idx->getType(),
369-
TrueRangeEnd-FirstTrueElement+1);
373+
Value *End =
374+
ConstantInt::get(Idx->getType(), TrueRangeEnd - FirstTrueElement + 1);
370375
return new ICmpInst(ICmpInst::ICMP_ULT, Idx, End);
371376
}
372377

@@ -380,8 +385,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
380385
Idx = Builder.CreateAdd(Idx, Offs);
381386
}
382387

383-
Value *End = ConstantInt::get(Idx->getType(),
384-
FalseRangeEnd-FirstFalseElement);
388+
Value *End =
389+
ConstantInt::get(Idx->getType(), FalseRangeEnd - FirstFalseElement);
385390
return new ICmpInst(ICmpInst::ICMP_UGT, Idx, End);
386391
}
387392

0 commit comments

Comments
 (0)