Duncan deftly points out that readnone functions aren't
authorChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 23:38:13 +0000 (23:38 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 23:38:13 +0000 (23:38 +0000)
invalidated by stores, so they can be handled as 'simple'
operations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122785 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/EarlyCSE.cpp
test/Transforms/EarlyCSE/basic.ll

index 6c2ea39896a682ae6815588afd5a211d452531d5..3d3f17b26fc6aff3db00b2ee9fb7b74ba64b3d79 100644 (file)
@@ -56,6 +56,9 @@ namespace {
     }
     
     static bool canHandle(Instruction *Inst) {
+      // This can only handle non-void readnone functions.
+      if (CallInst *CI = dyn_cast<CallInst>(Inst))
+        return CI->doesNotAccessMemory() && !CI->getType()->isVoidTy();
       return isa<CastInst>(Inst) || isa<BinaryOperator>(Inst) ||
              isa<GetElementPtrInst>(Inst) || isa<CmpInst>(Inst) ||
              isa<SelectInst>(Inst) || isa<ExtractElementInst>(Inst) ||
@@ -105,7 +108,8 @@ unsigned DenseMapInfo<SimpleValue>::getHashValue(SimpleValue Val) {
       Res ^= *I;
   } else {
     // nothing extra to hash in.
-    assert((isa<BinaryOperator>(Inst) || isa<GetElementPtrInst>(Inst) ||
+    assert((isa<CallInst>(Inst) ||
+            isa<BinaryOperator>(Inst) || isa<GetElementPtrInst>(Inst) ||
             isa<SelectInst>(Inst) || isa<ExtractElementInst>(Inst) ||
             isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst)) &&
            "Invalid/unknown instruction");
index bc152e706241ec7694213ffdf6bd90bab6326fd8..e3c75f97dcfcf497d280be2ae481b875631c0af5 100644 (file)
@@ -106,3 +106,16 @@ define void @test7(i32 *%P) {
   ; CHECK-NEXT: store i32 45
   ; CHECK-NEXT: ret void
 }
+
+;; Readnone functions aren't invalidated by stores.
+; CHECK: @test8
+define i32 @test8(i32 *%P) {
+  %V1 = call i32 @func(i32* %P) readnone
+  store i32 4, i32* %P
+  %V2 = call i32 @func(i32* %P) readnone
+  %Diff = sub i32 %V1, %V2
+  ret i32 %Diff
+  ; CHECK: ret i32 0
+}
+
+