[llvm-commits] [llvm] r122785 - in /llvm/trunk: lib/Transforms/Scalar/EarlyCSE.cpp test/Transforms/EarlyCSE/basic.ll
Chris Lattner
sabre at nondot.org
Mon Jan 3 15:38:13 PST 2011
Author: lattner
Date: Mon Jan 3 17:38:13 2011
New Revision: 122785
URL: http://llvm.org/viewvc/llvm-project?rev=122785&view=rev
Log:
Duncan deftly points out that readnone functions aren't
invalidated by stores, so they can be handled as 'simple'
operations.
Modified:
llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
llvm/trunk/test/Transforms/EarlyCSE/basic.ll
Modified: llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp?rev=122785&r1=122784&r2=122785&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp Mon Jan 3 17:38:13 2011
@@ -56,6 +56,9 @@
}
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 @@
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");
Modified: llvm/trunk/test/Transforms/EarlyCSE/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/EarlyCSE/basic.ll?rev=122785&r1=122784&r2=122785&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/EarlyCSE/basic.ll (original)
+++ llvm/trunk/test/Transforms/EarlyCSE/basic.ll Mon Jan 3 17:38:13 2011
@@ -106,3 +106,16 @@
; 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
+}
+
+
More information about the llvm-commits
mailing list