[llvm-commits] [patch] Add a pass for duplicating indirectbr at the IL level

Bob Wilson bob.wilson at apple.com
Mon Aug 1 09:12:13 PDT 2011


On Jul 30, 2011, at 7:27 PM, Rafael Ávila de Espíndola wrote:

>> Your patch is for an "indirect branch duplication" pass, but your
>> comments above suggest that you're planning to expand it to do much
>> more general IL-level tail duplication.  Which is it?  And why?  I
>> don't think it makes sense to have 3 separate taildup passes that are
>> all doing essentially the same thing at different points in the
>> compilation process.
> 
> I agree that we should not have all of them. I do intend to remove the
> MI one if this one works.

How do you define "works"?  You haven't provided a good explanation for why the LLVM IR level is a better place for tail duplication than the MI level.  Have you come up with a solution for the problem that you can't judge the code size of IR instructions?  I'd like to see a more detailed design proposal.

I realize, of course, that I haven't yet provided any details of my work, either.  I've got a bunch more pressing things to do this week, but I'll try to make progress soon.

>>> 
>>> BTW, what is your plan for duplicating into a conditional branch?
>>> I would be interested in implementing that too…
>> 
>> The problem I'm working on is specifically for indirect branches.  We
>> need to essentially undo the front-end's transformation to use a
>> single indirect branch per function.  (I'm actually including
>> branches through jump tables here.  Those don't get the same
>> treatment by the front-end, but the same motivation applies for
>> duplicating them in some cases.)  The current taildup approach is
>> very naive.  It cannot handle important cases like duplicating past
>> conditional branches, and in other cases, it duplicates far more than
>> necessary, which bloats code size and can hurt i-cache locality, etc.
>> The approach I'm taking it is to use dominance information to analyze
>> the CFG and find regions of code to duplicate in selected locations.
>> You would not want to do this for anything except indirect branches.
> 
> Sorry, the question was more on the "how to duplicate", not "where to
> duplicate". If previous optimizations gives us
> 
> zed:
> ...
> br i1 %foo, %indirectgoto, %bar
> 
> and you decide that the indirect goto should be duplicated to zed, how
> do you do it?

If you want to duplicate back "zed", you need to duplicate all the code between that point and the indirect branch.

>> I agree that a target-specific peephole is not the most elegant
>> solution, and I'm sure your new pass nicely solves the specific
>> problem you're looking at.  I just don't think we want to have 4
>> separate taildup/indirect-branch-dup passes (the 2 existing taildup
>> passes, plus yours, plus mine).
> 
> As I mentioned, my intention is to replace the existing early MI level one.
> 
> Cheers,
> Rafael





More information about the llvm-commits mailing list