diff options
author | Chris Lattner <sabre@nondot.org> | 2011-01-03 23:38:13 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-01-03 23:38:13 +0000 |
commit | e508dd4c75705f325764e1197854c0e83266a7ea (patch) | |
tree | d779457fcb395e7ce59e38f2f0dac349cd0b9e76 | |
parent | 7158e08b8e619f4dcac9834c57f5f8afd6eea2eb (diff) |
Duncan deftly points out that readnone functions aren't
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
-rw-r--r-- | lib/Transforms/Scalar/EarlyCSE.cpp | 6 | ||||
-rw-r--r-- | test/Transforms/EarlyCSE/basic.ll | 13 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/EarlyCSE.cpp b/lib/Transforms/Scalar/EarlyCSE.cpp index 6c2ea39896..3d3f17b26f 100644 --- a/lib/Transforms/Scalar/EarlyCSE.cpp +++ b/lib/Transforms/Scalar/EarlyCSE.cpp @@ -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"); diff --git a/test/Transforms/EarlyCSE/basic.ll b/test/Transforms/EarlyCSE/basic.ll index bc152e7062..e3c75f97dc 100644 --- a/test/Transforms/EarlyCSE/basic.ll +++ b/test/Transforms/EarlyCSE/basic.ll @@ -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 +} + + |