Index: lib/Analysis/ScalarEvolutionExpander.cpp =================================================================== --- lib/Analysis/ScalarEvolutionExpander.cpp +++ lib/Analysis/ScalarEvolutionExpander.cpp @@ -60,12 +60,10 @@ // instructions that might be inserted before BIP. if (BasicBlock::iterator(CI) != IP || BIP == IP) { // Create a new cast, and leave the old cast in place in case - // it is being used as an insert point. Clear its operand - // so that it doesn't hold anything live. + // it is being used as an insert point. Ret = CastInst::Create(Op, V, Ty, "", &*IP); Ret->takeName(CI); CI->replaceAllUsesWith(Ret); - CI->setOperand(0, UndefValue::get(V->getType())); break; } Ret = CI; Index: test/CodeGen/ARM/lsr-undef-in-binop.ll =================================================================== --- test/CodeGen/ARM/lsr-undef-in-binop.ll +++ test/CodeGen/ARM/lsr-undef-in-binop.ll @@ -0,0 +1,250 @@ +; REQUIRES: arm-registered-target +; RUN: opt -S -loop-reduce %s -o - | FileCheck %s + +; CHECK: [[LOAD:%[0-9]+]] = load i8*, i8** +; CHECK: [[NEW_CAST:%[0-9]+]] = ptrtoint i8* [[LOAD]] to i32 +; CHECK: [[OLD_CAST:%[0-9]+]] = ptrtoint i8* [[LOAD]] to i32 +; CHECK: sub i32 [[OLD_CAST]], [[NEW_CAST]] + +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" +target triple = "armv8-unknown-hurd-eabihf" + +%"class.std::__1::vector.182" = type { %"class.std::__1::__vector_base.183" } +%"class.std::__1::__vector_base.183" = type { i8*, i8*, %"class.std::__1::__compressed_pair.184" } +%"class.std::__1::__compressed_pair.184" = type { %"struct.std::__1::__compressed_pair_elem.185" } +%"struct.std::__1::__compressed_pair_elem.185" = type { i8* } +%"class.std::__1::__vector_base_common" = type { i8 } + +$vector_insert = comdat any + +declare i8* @Allocate(i32) local_unnamed_addr +declare void @Free(i8*) local_unnamed_addr +declare void @_ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv(%"class.std::__1::__vector_base_common"*) local_unnamed_addr +declare i8* @memmove(i8*, i8*, i32) local_unnamed_addr + +; Function Attrs: noimplicitfloat nounwind uwtable +define linkonce_odr i32 @vector_insert(%"class.std::__1::vector.182"*, [1 x i32], i8*, i8*) local_unnamed_addr #1 comdat align 2 { + %5 = extractvalue [1 x i32] %1, 0 + %6 = getelementptr inbounds %"class.std::__1::vector.182", %"class.std::__1::vector.182"* %0, i32 0, i32 0, i32 0 + %7 = load i8*, i8** %6, align 4 + %8 = bitcast %"class.std::__1::vector.182"* %0 to i32* + %9 = ptrtoint i8* %7 to i32 + %10 = sub i32 %5, %9 + %11 = getelementptr inbounds i8, i8* %7, i32 %10 + %12 = ptrtoint i8* %3 to i32 + %13 = ptrtoint i8* %2 to i32 + %14 = sub i32 %12, %13 + %15 = icmp sgt i32 %14, 0 + br i1 %15, label %18, label %16 + +;