[LLVMdev] [RFC] Invariants in LLVM
Philip Reames
listmail at philipreames.com
Thu Jul 17 14:38:10 PDT 2014
On 07/17/2014 01:51 PM, Chandler Carruth wrote:
>
>
> 2. Would adding a canonicalization of if(c) { unreachable } to
> llvm.invariant(c) would be worthwhile?
>
>
> There was a long and painful attempt to implement invariants based on
> the branch-to-unreachable pattern. It didn't work. I don't expect
> these patterns to show up often organically and to go away too soon in
> the optimizer to be useful. The whole point of 'llvm.invariant'
> instead of the if construct is to distinguish between the case the
> optimizer should try to remove (a branch to unreachable) and the case
> the optimizer should try to preserve because of some specific utility.
> We shouldn't lose this important distinction.
On first thought, I disagree. I may not be understanding your point though.
My understanding of the previous work was that it tried to use
"branch-to-unreachable" as the canonical form. This is inherently
problematic in an IR based on basic blocks since it split basic blocks
into many smaller chunks. It might work out better if we used extended
basic blocks, but we don't.
I don't see any harm in canonicalizing to "llvm.invariant" from "if(c)
unreachable". In either case, we remove the branch and can merge the
basic blocks. In the former, we preserve more information for later
passes. The only real downside is potentially keeping more Values alive
and thus forcing the compiler to do more work.
Can you spell out your objections more?
>
>
> 2. We might want to have passes precompute the Value->(set of
> Invariants) map, and update it as necessary instead of doing
> transitive-user searches [a suggestion by Chandler].
>
>
> I think this is mostly just a small API tweak to make the code more
> maintainable. I'm specifically *not* imagining this as a formal
> analysis pass or anything of the sort.
I would support this.
I'm not seeing the downside to an analysis pass. Probably not worth
implementing up front, but might be worthwhile down the road.
Philip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140717/c3f0ceef/attachment.html>
More information about the llvm-dev
mailing list