@@ -127,8 +127,10 @@ bool GEPOperator::accumulateConstantOffset(
127127 // Fast path for canonical getelementptr i8 form.
128128 if (SourceType->isIntegerTy (8 ) && !ExternalAnalysis) {
129129 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+ }
132134 }
133135 return false ;
134136 }
@@ -163,28 +165,30 @@ bool GEPOperator::accumulateConstantOffset(
163165 Value *V = GTI.getOperand ();
164166 StructType *STy = GTI.getStructTypeOrNull ();
165167 // 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)))
181189 return false ;
182190 continue ;
183191 }
184- if (!AccumulateOffset (ConstOffset->getValue (),
185- GTI.getSequentialElementStride (DL)))
186- return false ;
187- continue ;
188192 }
189193
190194 // The operand is not constant, check if an external analysis was provided.
0 commit comments