@@ -111,8 +111,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
111
111
LoadInst *LI, GetElementPtrInst *GEP, GlobalVariable *GV, CmpInst &ICI,
112
112
ConstantInt *AndCst) {
113
113
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 ())
116
116
return nullptr ;
117
117
118
118
Constant *Init = GV->getInitializer ();
@@ -128,8 +128,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
128
128
// the simple index into a single-dimensional array.
129
129
//
130
130
// 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 )) ||
133
132
!cast<ConstantInt>(GEP->getOperand (1 ))->isZero () ||
134
133
isa<Constant>(GEP->getOperand (2 )))
135
134
return nullptr ;
@@ -142,15 +141,18 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
142
141
Type *EltTy = Init->getType ()->getArrayElementType ();
143
142
for (unsigned i = 3 , e = GEP->getNumOperands (); i != e; ++i) {
144
143
ConstantInt *Idx = dyn_cast<ConstantInt>(GEP->getOperand (i));
145
- if (!Idx) return nullptr ; // Variable index.
144
+ if (!Idx)
145
+ return nullptr ; // Variable index.
146
146
147
147
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.
149
150
150
151
if (StructType *STy = dyn_cast<StructType>(EltTy))
151
152
EltTy = STy->getElementType (IdxVal);
152
153
else if (ArrayType *ATy = dyn_cast<ArrayType>(EltTy)) {
153
- if (IdxVal >= ATy->getNumElements ()) return nullptr ;
154
+ if (IdxVal >= ATy->getNumElements ())
155
+ return nullptr ;
154
156
EltTy = ATy->getElementType ();
155
157
} else {
156
158
return nullptr ; // Unknown type.
@@ -191,7 +193,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
191
193
Constant *CompareRHS = cast<Constant>(ICI.getOperand (1 ));
192
194
for (unsigned i = 0 , e = ArrayElementCount; i != e; ++i) {
193
195
Constant *Elt = Init->getAggregateElement (i);
194
- if (!Elt) return nullptr ;
196
+ if (!Elt)
197
+ return nullptr ;
195
198
196
199
// If this is indexing an array of structures, get the structure element.
197
200
if (!LaterIndices.empty ()) {
@@ -214,16 +217,17 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
214
217
if (isa<UndefValue>(C)) {
215
218
// Extend range state machines to cover this element in case there is an
216
219
// undef in the middle of the range.
217
- if (TrueRangeEnd == (int )i- 1 )
220
+ if (TrueRangeEnd == (int )i - 1 )
218
221
TrueRangeEnd = i;
219
- if (FalseRangeEnd == (int )i- 1 )
222
+ if (FalseRangeEnd == (int )i - 1 )
220
223
FalseRangeEnd = i;
221
224
continue ;
222
225
}
223
226
224
227
// If we can't compute the result for any of the elements, we have to give
225
228
// up evaluating the entire conditional.
226
- if (!isa<ConstantInt>(C)) return nullptr ;
229
+ if (!isa<ConstantInt>(C))
230
+ return nullptr ;
227
231
228
232
// Otherwise, we know if the comparison is true or false for this element,
229
233
// update our state machines.
@@ -233,7 +237,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
233
237
if (IsTrueForElt) {
234
238
// Update the TrueElement state machine.
235
239
if (FirstTrueElement == Undefined)
236
- FirstTrueElement = TrueRangeEnd = i; // First true element.
240
+ FirstTrueElement = TrueRangeEnd = i; // First true element.
237
241
else {
238
242
// Update double-compare state machine.
239
243
if (SecondTrueElement == Undefined)
@@ -242,7 +246,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
242
246
SecondTrueElement = Overdefined;
243
247
244
248
// Update range state machine.
245
- if (TrueRangeEnd == (int )i- 1 )
249
+ if (TrueRangeEnd == (int )i - 1 )
246
250
TrueRangeEnd = i;
247
251
else
248
252
TrueRangeEnd = Overdefined;
@@ -259,7 +263,7 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
259
263
SecondFalseElement = Overdefined;
260
264
261
265
// Update range state machine.
262
- if (FalseRangeEnd == (int )i- 1 )
266
+ if (FalseRangeEnd == (int )i - 1 )
263
267
FalseRangeEnd = i;
264
268
else
265
269
FalseRangeEnd = Overdefined;
@@ -348,7 +352,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
348
352
349
353
// False for two elements -> 'i != 47 & i != 72'.
350
354
Value *C1 = Builder.CreateICmpNE (Idx, FirstFalseIdx);
351
- Value *SecondFalseIdx = ConstantInt::get (Idx->getType (),SecondFalseElement);
355
+ Value *SecondFalseIdx =
356
+ ConstantInt::get (Idx->getType (), SecondFalseElement);
352
357
Value *C2 = Builder.CreateICmpNE (Idx, SecondFalseIdx);
353
358
return BinaryOperator::CreateAnd (C1, C2);
354
359
}
@@ -365,8 +370,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
365
370
Idx = Builder.CreateAdd (Idx, Offs);
366
371
}
367
372
368
- Value *End = ConstantInt::get (Idx-> getType (),
369
- TrueRangeEnd- FirstTrueElement+ 1 );
373
+ Value *End =
374
+ ConstantInt::get (Idx-> getType (), TrueRangeEnd - FirstTrueElement + 1 );
370
375
return new ICmpInst (ICmpInst::ICMP_ULT, Idx, End);
371
376
}
372
377
@@ -380,8 +385,8 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
380
385
Idx = Builder.CreateAdd (Idx, Offs);
381
386
}
382
387
383
- Value *End = ConstantInt::get (Idx-> getType (),
384
- FalseRangeEnd- FirstFalseElement);
388
+ Value *End =
389
+ ConstantInt::get (Idx-> getType (), FalseRangeEnd - FirstFalseElement);
385
390
return new ICmpInst (ICmpInst::ICMP_UGT, Idx, End);
386
391
}
387
392
0 commit comments