[llvm-dev] [GVN] same sequence of instructions in if and else branch

Taewook Oh via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 9 11:42:59 PST 2016

There is a phi-node "%phi = phi i64 [%cast1, %if], [%cast2, %else]" in the common successor. The actual control flow is a bit more complex, but there is a common successor block, and %cast1 and %cast2 are the two values that the phi node in the common successor takes.

Does the existence of the phi node affect optimization?


From: <mats.o.petersson at googlemail.com<mailto:mats.o.petersson at googlemail.com>> on behalf of mats petersson <mats at planetcatfish.com<mailto:mats at planetcatfish.com>>
Date: Tuesday, February 9, 2016 at 11:34 AM
To: Taewook Oh <twoh at fb.com<mailto:twoh at fb.com>>
Cc: "llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>" <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>
Subject: Re: [llvm-dev] [GVN] same sequence of instructions in if and else branch

And there's no PHI node after this that depends on the condition?


On 9 February 2016 at 19:30, Taewook Oh via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:


I found that GVN doesn't promote identical sequence of instructions in if and else branch to their common predecessors. For example, for the following code snippet



br i1 %cmp, label %if, label %else


%incdec.ptr.1 = getelementptr inbounds i8, i8* %ptr, i64 1

%cast1 = ptrtoint i8* %incdec.ptr.1 to i64



%incdec.ptr.2 = getelementptr inbounds i8, i8* %ptr, i64 1

%cast2 = ptrtoint i8* %incdec.ptr.2 to i64

GVN doesn't move instructions in 'if' and 'else' blocks to 'pred' block even though it knows that incdec.ptr.1/case1 has a same value number with incdec.ptr.2/cast2. I see a case where this kind of redundancy confuses following optimization passes and ends up generating suboptimal code.

>From the GVN implementation, it seems that transformation is performed only when the "leader" value dominates the other value, so it cannot handle a case like the above example. I wonder if this is by design or just a missing feature.



LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160209/d1ca226d/attachment.html>

More information about the llvm-dev mailing list