From: Evan Cheng Date: Thu, 13 Dec 2007 03:32:53 +0000 (+0000) Subject: Be extra careful with extension use optimation. Now turned on by default. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=f9785f92b630e69262c395b2fc0893451169d68b Be extra careful with extension use optimation. Now turned on by default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44981 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 47e60cd74b4..8da09127e96 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -36,7 +36,7 @@ using namespace llvm; namespace { cl::opt OptExtUses("optimize-ext-uses", - cl::init(false), cl::Hidden); + cl::init(true), cl::Hidden); } namespace { @@ -929,6 +929,10 @@ bool CodeGenPrepare::OptimizeExtUses(Instruction *I) { if (Src->hasOneUse()) return false; + // Only do this xform is truncating is free. + if (!TLI->isTruncateFree(I->getType(), Src->getType())) + return false; + // Only safe to perform the optimization if the source is also defined in // this block. if (!isa(Src) || DefBB != cast(Src)->getParent()) @@ -952,8 +956,11 @@ bool CodeGenPrepare::OptimizeExtUses(Instruction *I) { for (Value::use_iterator UI = Src->use_begin(), E = Src->use_end(); UI != E; ++UI) { Instruction *User = cast(*UI); - if (User->getParent() == DefBB) continue; - if (isa(User)) + BasicBlock *UserBB = User->getParent(); + if (UserBB == DefBB) continue; + // Be conservative. We don't want this xform to end up introducing + // reloads just before load / store instructions. + if (isa(User) || isa(User) || isa(User)) return false; } diff --git a/test/CodeGen/X86/opt-ext-uses.ll b/test/CodeGen/X86/opt-ext-uses.ll index faa9be75504..322850c5523 100644 --- a/test/CodeGen/X86/opt-ext-uses.ll +++ b/test/CodeGen/X86/opt-ext-uses.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | llc -march=x86 -optimize-ext-uses=true | grep movw | count 1 +; RUN: llvm-as < %s | llc -march=x86 | grep movw | count 1 define i16 @t() signext { entry: