From: Eugene Leviant Date: Wed, 3 Jul 2019 09:36:32 +0000 (+0000) Subject: [SCEV][LSR] Prevent using undefined value in binops X-Git-Tag: android-x86-9.0-r1~917 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=39e1a0dcf26e496562909449465f12e5e36a7b2e;p=android-x86%2Fexternal-llvm.git [SCEV][LSR] Prevent using undefined value in binops On some occasions ReuseOrCreateCast may convert previously expanded value to undefined. That value may be passed by SCEVExpander as an argument to InsertBinop making IV chain undefined. Differential revision: https://reviews.llvm.org/D63928 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365009 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index cd323fcb897..16d0bd64bf0 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -60,12 +60,10 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty, // 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; diff --git a/test/CodeGen/ARM/lsr-undef-in-binop.ll b/test/CodeGen/ARM/lsr-undef-in-binop.ll new file mode 100644 index 00000000000..564328d9999 --- /dev/null +++ b/test/CodeGen/ARM/lsr-undef-in-binop.ll @@ -0,0 +1,251 @@ +; REQUIRES: arm-registered-target +; RUN: opt -S -loop-reduce %s -o - | FileCheck %s + +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 { +; CHECK-LABEL: vector_insert + %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 +; CHECK: [[LOAD:%[0-9]+]] = load i8*, i8** + %8 = bitcast %"class.std::__1::vector.182"* %0 to i32* + %9 = ptrtoint i8* %7 to i32 +; CHECK: [[NEW_CAST:%[0-9]+]] = ptrtoint i8* [[LOAD]] to i32 +; CHECK: [[OLD_CAST:%[0-9]+]] = ptrtoint i8* [[LOAD]] 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 + +;