diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -3901,7 +3901,8 @@ if (auto *SI = dyn_cast_or_null(I)) { // Store instruction with index and scale costs 2 Uops. // Check the preceding GEP to identify non-const indices. - if (auto *GEP = dyn_cast(SI->getPointerOperand())) { + if (auto *GEP = dyn_cast( + SI->getPointerOperand()->stripPointerCasts())) { if (!all_of(GEP->indices(), [](Value *V) { return isa(V); })) return TTI::TCC_Basic * 2; } diff --git a/llvm/test/Transforms/LoopUnroll/X86/store_cost.ll b/llvm/test/Transforms/LoopUnroll/X86/store_cost.ll --- a/llvm/test/Transforms/LoopUnroll/X86/store_cost.ll +++ b/llvm/test/Transforms/LoopUnroll/X86/store_cost.ll @@ -46,7 +46,9 @@ store i32 %val4, i32* %xptr4 %val5 = add i32 %counter, 10 %xptr5 = getelementptr [1024 x i32], [1024 x i32]* %x05, i32 0, i32 %counter - store i32 %val5, i32* %xptr5 + %bc = bitcast i32* %xptr5 to i16* + %val5trunc = trunc i32 %val5 to i16 + store i16 %val5trunc, i16* %bc br label %loop.inc loop.inc: