[llvm-commits] CVS: llvm/lib/Analysis/ScalarEvolution.cpp

Chris Lattner clattner at apple.com
Mon Dec 4 10:35:20 PST 2006


Reid, I don't like this series of patches.  You're replacing one evil  
with another.  Please endeavor to figure out what type of cast is  
actually needed and put it in, rather than changing one sort of  
inferred cast into another.


> Index: llvm/lib/Analysis/ScalarEvolution.cpp
> diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.61 llvm/lib/ 
> Analysis/ScalarEvolution.cpp:1.62
> --- llvm/lib/Analysis/ScalarEvolution.cpp:1.61	Fri Dec  1 20:22:01  
> 2006
> +++ llvm/lib/Analysis/ScalarEvolution.cpp	Mon Dec  4 11:05:42 2006
> @@ -178,7 +178,8 @@
>    // Make sure that SCEVConstant instances are all unsigned.
>    if (V->getType()->isSigned()) {
>      const Type *NewTy = V->getType()->getUnsignedVersion();
> -    V = cast<ConstantInt>(ConstantExpr::getCast(V, NewTy));
> +    V = cast<ConstantInt>(
> +        ConstantExpr::getInferredCast(V, false, NewTy, false));
>    }

This is always a bitcast.

>    SCEVConstant *&R = (*SCEVConstants)[V];
> @@ -465,7 +466,7 @@
>      C = ConstantInt::get(Ty, Val);
>    else {
>      C = ConstantInt::get(Ty->getSignedVersion(), Val);
> -    C = ConstantExpr::getCast(C, Ty);
> +    C = ConstantExpr::getInferredCast(C, true, Ty, false);

With your constantint changes, you can just replace:

   else if (Ty->isSigned())
     C = ConstantInt::get(Ty, Val);
   else {
     C = ConstantInt::get(Ty->getSignedVersion(), Val);
     C = ConstantExpr::getInferredCast(C, true, Ty, false);
   }

with:

   else
     C = ConstantInt::get(Ty, Val);

Even if you kept the cast (which you shouldn't), it is always a bitcast.

> @@ -511,7 +512,8 @@
>      for (; NumSteps; --NumSteps)
>        Result *= Val-(NumSteps-1);
>      Constant *Res = ConstantInt::get(Type::ULongTy, Result);
> -    return SCEVUnknown::get(ConstantExpr::getCast(Res, V->getType 
> ()));
> +    return SCEVUnknown::get(
> +        ConstantExpr::getInferredCast(Res, false, V->getType(),  
> true));

I'd rather this be written as:

      if (V->getType() != Type::ULongTy)
        Res = ConstantExpr::getCast(Truncate, Res, V->getType());
      return Res;

>    }
>
>    const Type *Ty = V->getType();
> @@ -996,10 +998,11 @@
>        Constant *LHSCV = LHSC->getValue();
>        Constant *RHSCV = RHSC->getValue();
>        if (LHSCV->getType()->isUnsigned())
> -        LHSCV = ConstantExpr::getCast(LHSCV,
> -                                      LHSCV->getType()- 
> >getSignedVersion());
> +        LHSCV = ConstantExpr::getInferredCast(
> +            LHSCV, false, LHSCV->getType()->getSignedVersion(),  
> true);
>        if (RHSCV->getType()->isUnsigned())
> -        RHSCV = ConstantExpr::getCast(RHSCV, LHSCV->getType());
> +        RHSCV = ConstantExpr::getInferredCast(
> +            RHSCV, false, LHSCV->getType(), true);
>        return SCEVUnknown::get(ConstantExpr::getSDiv(LHSCV, RHSCV));
>      }
>    }

This is all dead now that types are signless for div, replace it with:

       return SCEVUnknown::get(ConstantExpr::getSDiv(LHSC->getValue 
(), RHSC->getValue()));

-Chris



More information about the llvm-commits mailing list