[llvm-commits] [llvm] r75571 - in /llvm/trunk: lib/Transforms/Scalar/SimplifyCFGPass.cpp test/Transforms/SimplifyCFG/2009-07-13-no-delete-asm.ll

Dale Johannesen dalej at apple.com
Mon Jul 13 17:45:38 PDT 2009


Author: johannes
Date: Mon Jul 13 19:45:38 2009
New Revision: 75571

URL: http://llvm.org/viewvc/llvm-project?rev=75571&view=rev
Log:
Don't delete asm's just because their inputs are undefined;
xor R, R is a common and valid idiom for zeroing a register, for example.


Added:
    llvm/trunk/test/Transforms/SimplifyCFG/2009-07-13-no-delete-asm.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp?rev=75571&r1=75570&r2=75571&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp Mon Jul 13 19:45:38 2009
@@ -109,6 +109,8 @@
     if (!Reachable.insert(BB))
       continue;
 
+    bool AsmFound = false;
+    StoreInst *UndefStore = 0;
     // Do a quick scan of the basic block, turning any obviously unreachable
     // instructions into LLVM unreachable insts.  The instruction combining pass
     // canonicalizes unreachable insts into stores to null or undef.
@@ -125,20 +127,27 @@
           }
           break;
         }
+        if (isa<InlineAsm>(CI->getOperand(0)))
+          AsmFound = true;
       }
       
       if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
         Value *Ptr = SI->getOperand(1);
-        
-        if (isa<UndefValue>(Ptr) ||
-            (isa<ConstantPointerNull>(Ptr) &&
-             cast<PointerType>(Ptr->getType())->getAddressSpace() == 0)) {
-          ChangeToUnreachable(SI, Context);
-          Changed = true;
-          break;
-        }
+
+        if ((isa<UndefValue>(Ptr) ||
+             (isa<ConstantPointerNull>(Ptr) &&
+              cast<PointerType>(Ptr->getType())->getAddressSpace() == 0)) &&
+            !UndefStore)
+          UndefStore = SI;
       }
     }
+    // We can't delete asm's just because their inputs are undefined;
+    // xor R, R is a common idiom for zeroing a register, for example.
+    // Assume user knows what he is doing.
+    if (UndefStore && !AsmFound) {
+      ChangeToUnreachable(UndefStore, Context);
+      Changed = true;
+    }
 
     // Turn invokes that call 'nounwind' functions into ordinary calls.
     if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))

Added: llvm/trunk/test/Transforms/SimplifyCFG/2009-07-13-no-delete-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/2009-07-13-no-delete-asm.ll?rev=75571&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/2009-07-13-no-delete-asm.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyCFG/2009-07-13-no-delete-asm.ll Mon Jul 13 19:45:38 2009
@@ -0,0 +1,11 @@
+; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | grep xor
+; ModuleID = '<stdin>'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+
+define void @bar() nounwind {
+entry:
+	store i16 undef, i16* null
+	%asmtmp = call i32 asm sideeffect "xor $0, $0", "=={bx},rm,~{dirflag},~{fpsr},~{flags},~{memory}"(i16 undef) nounwind		; <i32> [#uses=0]
+	ret void
+}





More information about the llvm-commits mailing list