@@ -127,8 +127,10 @@ bool GEPOperator::accumulateConstantOffset(
127
127
// Fast path for canonical getelementptr i8 form.
128
128
if (SourceType->isIntegerTy (8 ) && !ExternalAnalysis) {
129
129
if (auto *CI = dyn_cast<ConstantInt>(Index.front ())) {
130
- Offset += CI->getValue ().sextOrTrunc (Offset.getBitWidth ());
131
- return true ;
130
+ if (CI->getType ()->isIntegerTy ()) {
131
+ Offset += CI->getValue ().sextOrTrunc (Offset.getBitWidth ());
132
+ return true ;
133
+ }
132
134
}
133
135
return false ;
134
136
}
@@ -163,28 +165,30 @@ bool GEPOperator::accumulateConstantOffset(
163
165
Value *V = GTI.getOperand ();
164
166
StructType *STy = GTI.getStructTypeOrNull ();
165
167
// Handle ConstantInt if possible.
166
- if (auto ConstOffset = dyn_cast<ConstantInt>(V)) {
167
- if (ConstOffset->isZero ())
168
- continue ;
169
- // if the type is scalable and the constant is not zero (vscale * n * 0 =
170
- // 0) bailout.
171
- if (ScalableType)
172
- return false ;
173
- // Handle a struct index, which adds its field offset to the pointer.
174
- if (STy) {
175
- unsigned ElementIdx = ConstOffset->getZExtValue ();
176
- const StructLayout *SL = DL.getStructLayout (STy);
177
- // Element offset is in bytes.
178
- if (!AccumulateOffset (
179
- APInt (Offset.getBitWidth (), SL->getElementOffset (ElementIdx)),
180
- 1 ))
168
+ if (V->getType ()->isIntegerTy ()) {
169
+ if (auto ConstOffset = dyn_cast<ConstantInt>(V)) {
170
+ if (ConstOffset->isZero ())
171
+ continue ;
172
+ // if the type is scalable and the constant is not zero (vscale * n * 0
173
+ // = 0) bailout.
174
+ if (ScalableType)
175
+ return false ;
176
+ // Handle a struct index, which adds its field offset to the pointer.
177
+ if (STy) {
178
+ unsigned ElementIdx = ConstOffset->getZExtValue ();
179
+ const StructLayout *SL = DL.getStructLayout (STy);
180
+ // Element offset is in bytes.
181
+ if (!AccumulateOffset (
182
+ APInt (Offset.getBitWidth (), SL->getElementOffset (ElementIdx)),
183
+ 1 ))
184
+ return false ;
185
+ continue ;
186
+ }
187
+ if (!AccumulateOffset (ConstOffset->getValue (),
188
+ GTI.getSequentialElementStride (DL)))
181
189
return false ;
182
190
continue ;
183
191
}
184
- if (!AccumulateOffset (ConstOffset->getValue (),
185
- GTI.getSequentialElementStride (DL)))
186
- return false ;
187
- continue ;
188
192
}
189
193
190
194
// The operand is not constant, check if an external analysis was provided.
0 commit comments