Index: lib/Target/AArch64/AArch64FastISel.cpp =================================================================== --- lib/Target/AArch64/AArch64FastISel.cpp +++ lib/Target/AArch64/AArch64FastISel.cpp @@ -4832,7 +4832,7 @@ for (auto OI = std::next(I->op_begin()), E = I->op_end(); OI != E; ++OI) { const Value *Idx = *OI; if (auto *StTy = dyn_cast(Ty)) { - unsigned Field = cast(Idx)->getZExtValue(); + uint64_t Field = cast(Idx)->getZExtValue(); // N = N + Offset if (Field) TotalOffs += DL.getStructLayout(StTy)->getElementOffset(Field); @@ -4844,8 +4844,8 @@ if (CI->isZero()) continue; // N = N + Offset - TotalOffs += - DL.getTypeAllocSize(Ty) * cast(CI)->getSExtValue(); + uint64_t IdxN = CI->getValue().sextOrTrunc(64).getSExtValue(); + TotalOffs += DL.getTypeAllocSize(Ty) * IdxN; continue; } if (TotalOffs) { Index: test/CodeGen/X86/getelementptr.ll =================================================================== --- test/CodeGen/X86/getelementptr.ll +++ test/CodeGen/X86/getelementptr.ll @@ -1,7 +1,19 @@ ; RUN: llc < %s -O0 -march=x86 ; RUN: llc < %s -O0 -march=x86-64 +; RUN: llc < %s -O0 -march=arm64 +; RUN: llc < %s -O0 -march=mips64 +; RUN: llc < %s -O0 -march=ppc64 +; RUN: llc < %s -O0 -march=hexagon +; RUN: llc < %s -O0 -march=sparc +; RUN: llc < %s -O0 -march=systemz ; RUN: llc < %s -O2 -march=x86 ; RUN: llc < %s -O2 -march=x86-64 +; RUN: llc < %s -O2 -march=arm64 +; RUN: llc < %s -O2 -march=mips64 +; RUN: llc < %s -O2 -march=ppc64 +; RUN: llc < %s -O2 -march=hexagon +; RUN: llc < %s -O2 -march=sparc +; RUN: llc < %s -O2 -march=systemz ; Test big index trunc to pointer size: