[llvm-commits] [PATCH] InstCombine enhancement

Eli Friedman eli.friedman at gmail.com
Mon Nov 26 13:51:28 PST 2012


On Mon, Nov 26, 2012 at 1:32 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
> Hi, dear all:
>
>      This change is trying to catch this optimization opportunity (one of
> the two defects reported in rdar://12329730):
>
>    -----------------------------------------------------
>           ((X^C1) >> C2) ^ C3  => (X>>C2) ^ ((C1>>C2)^C3)
>      where the subexpression "X ^ C1" has more than one uses, and
>      "(X^C1) >> C2" has single use.
>   ------------------------------------------------------
>
>     If the "X ^ C1" has only one use,  InstCombine will distribute the ">>"
> operation
> in the "X^C1 >> C2", and the entire expression would be eventually
> optimized;
> however, if "X ^ C1" has multiple uses,  InstCombine would give up.

For new code, please use the matchers defined in
llvm/Support/PatternMatch.h (m_Xor etc.), which tend to be more
compact than dyn_cast for this sort of matching.

Are there any cases where this transformation could make us generate
worse code?  If so, how likely do you think it is to happen in
practice?

This seems to be a general pattern which could be applied to many
operations (at least "&", "|", "+", "-").  It also seems to apply to
other shift operations (shl, ashr).  Which of those cases do we handle
already?  How hard would it be to generalize this transformation?

-Eli



More information about the llvm-commits mailing list