From: Piotr Padlewski Date: Tue, 25 Aug 2015 01:34:15 +0000 (+0000) Subject: Assume intrinsic handling in global opt X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8e6aecec255db5858a7abcc22a2d287a368883fa;p=oota-llvm.git Assume intrinsic handling in global opt It doesn't solve the problem, when for example we load something, and then assume that it is the same as some constant value, because globalopt will fail on unknown load instruction. The proposed solution would be to skip some instructions that we can't evaluate and they are safe to skip (f.e. load, assume and many others) and see if they are required to perform optimization (f.e. we don't care about ephemeral instructions that may appear using @llvm.assume()) http://reviews.llvm.org/D12266 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245919 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index af19e7d3b4e..c60b3ccc298 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2504,6 +2504,10 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, // Continue even if we do nothing. ++CurInst; continue; + } else if (II->getIntrinsicID() == Intrinsic::assume) { + DEBUG(dbgs() << "Skipping assume intrinsic.\n"); + ++CurInst; + continue; } DEBUG(dbgs() << "Unknown intrinsic. Can not evaluate.\n"); diff --git a/test/Transforms/GlobalOpt/assume.ll b/test/Transforms/GlobalOpt/assume.ll new file mode 100644 index 00000000000..59e80b1c554 --- /dev/null +++ b/test/Transforms/GlobalOpt/assume.ll @@ -0,0 +1,21 @@ +; RUN: opt -S -globalopt < %s | FileCheck %s + +; CHECK: @tmp = global i32 42 + +@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }] +@tmp = global i32 0 + +define i32 @TheAnswerToLifeTheUniverseAndEverything() { + ret i32 42 +} + +define void @_GLOBAL__I_a() i8* undef { +enter: + %tmp1 = call i32 @TheAnswerToLifeTheUniverseAndEverything() + store i32 %tmp1, i32* @tmp + %cmp = icmp eq i32 %tmp1, 42 + call void @llvm.assume(i1 %cmp) + ret void +} + +declare void @llvm.assume(i1)