Be extra careful with extension use optimation. Now turned on by default.
authorEvan Cheng <evan.cheng@apple.com>
Thu, 13 Dec 2007 03:32:53 +0000 (03:32 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 13 Dec 2007 03:32:53 +0000 (03:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44981 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/CodeGenPrepare.cpp
test/CodeGen/X86/opt-ext-uses.ll

index 47e60cd74b4d50dd540a920114afcdc8d508d4c6..8da09127e96c3077203bf1da39415451241f8991 100644 (file)
@@ -36,7 +36,7 @@ using namespace llvm;
 
 namespace {
   cl::opt<bool> 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<Instruction>(Src) || DefBB != cast<Instruction>(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<Instruction>(*UI);
-    if (User->getParent() == DefBB) continue;
-    if (isa<PHINode>(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<PHINode>(User) || isa<LoadInst>(User) || isa<StoreInst>(User))
       return false;
   }
 
index faa9be75504a8e7ae82f44d26db71baa8ae89cf1..322850c5523f3381b45d7e1668062341fc90122a 100644 (file)
@@ -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: