From e508dd4c75705f325764e1197854c0e83266a7ea Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 3 Jan 2011 23:38:13 +0000 Subject: [PATCH] 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 --- lib/Transforms/Scalar/EarlyCSE.cpp | 6 +++++- test/Transforms/EarlyCSE/basic.ll | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/EarlyCSE.cpp b/lib/Transforms/Scalar/EarlyCSE.cpp index 6c2ea39896a..3d3f17b26fc 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(Inst)) + return CI->doesNotAccessMemory() && !CI->getType()->isVoidTy(); return isa(Inst) || isa(Inst) || isa(Inst) || isa(Inst) || isa(Inst) || isa(Inst) || @@ -105,7 +108,8 @@ unsigned DenseMapInfo::getHashValue(SimpleValue Val) { Res ^= *I; } else { // nothing extra to hash in. - assert((isa(Inst) || isa(Inst) || + assert((isa(Inst) || + isa(Inst) || isa(Inst) || isa(Inst) || isa(Inst) || isa(Inst) || isa(Inst)) && "Invalid/unknown instruction"); diff --git a/test/Transforms/EarlyCSE/basic.ll b/test/Transforms/EarlyCSE/basic.ll index bc152e70624..e3c75f97dcf 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 +} + + -- 2.34.1