[llvm-commits] [PATCH] fold umax(zext A, zext B) -> zext (umax(A, B))

Dan Gohman gohman at apple.com
Wed Jun 17 13:25:25 PDT 2009


On Jun 17, 2009, at 11:35 AM, Török Edwin wrote:

> Hi,
>
> I noticed that umax (zext t1 %X to %t0, zext t1 %Y to %t0) isn't  
> folded,
> the attached patch folds this into:
> umax (zext t1 %X to %t0, zext t1 %Y to %t0).
>
> It also folds umax (sext t1 %X to %t0, sext t1 %Y to %t0) ->  sext t1
> (umax (%X, %Y)) to %t0.
>
> zext is very often encountered in SCEV expressions on x86-64, since
> pointer indexes for GEP are i64.
>
> Thoughts?

Another question to ask is whether this kind of thing belongs in
ScalarEvolution, or if it would be more appropriate for
instcombine. Instcombine looks at all instructions in a program,
while ScalarEvolution typically only looks at those related to
loop iteration. Also, instcombine could more easily handle more
generalized cases of this optimization, for example with umin.

On the other hand, there are cases where it makes sense to do
such simplifications in ScalarEvolution. Can you given an
example where you're seeing this kind of code?

One minor note on the patch itself:

 > +      unsigned bits = Ty->getPrimitiveSizeInBits();
 > +      if (!bits) {
[...]
 > +    if (maxBits) {

Within ScalarEvolution code, you can use
ScalarEvolution::getTypeSizeInBits, which has the advantage of
TargetData information (when available). Using that instead
of getPrimitiveSizeInBits would eliminate the need for the
two if statements quoted here.

Dan





More information about the llvm-commits mailing list