diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -591,7 +591,9 @@ if (isa(IP)) ScanLimit++; if (IP->getOpcode() == Instruction::GetElementPtr && - IP->getOperand(0) == V && IP->getOperand(1) == Idx) + IP->getOperand(0) == V && IP->getOperand(1) == Idx && + cast(&*IP)->getSourceElementType() == + Type::getInt8Ty(Ty->getContext())) return &*IP; if (IP == BlockBegin) break; } diff --git a/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll b/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll --- a/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll +++ b/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll @@ -8,12 +8,13 @@ ; CHECK-NEXT: entry: ; CHECK-NEXT: [[O:%.*]] = getelementptr ptr, ptr [[ARG:%.*]], i64 16 ; CHECK-NEXT: call void @c(ptr [[O]]) +; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, ptr [[ARG]], i64 16 ; CHECK-NEXT: br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[LOOP]] ] ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[IDX]], 1 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[INC]], 16 -; CHECK-NEXT: call void @c(ptr [[O]]) +; CHECK-NEXT: call void @c(ptr [[UGLYGEP]]) ; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[END:%.*]] ; CHECK: end: ; CHECK-NEXT: ret void