[llvm] 903c3d2 - [SCEVExpander] Always use i8 GEP for reused value offset

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 26 16:53:48 PST 2022


Yeah!

Philip

On 1/26/22 6:39 AM, Nikita Popov via llvm-commits wrote:
> Author: Nikita Popov
> Date: 2022-01-26T15:38:58+01:00
> New Revision: 903c3d2863b9d0ae760a2f45e0e934f1d12cd1d4
>
> URL: https://github.com/llvm/llvm-project/commit/903c3d2863b9d0ae760a2f45e0e934f1d12cd1d4
> DIFF: https://github.com/llvm/llvm-project/commit/903c3d2863b9d0ae760a2f45e0e934f1d12cd1d4.diff
>
> LOG: [SCEVExpander] Always use i8 GEP for reused value offset
>
> We could keep the non-i8 GEP code for non-opaque pointers, but
> there's two reasons I'm dropping it: First, this actually appears
> to be dead code, at least it isn't hit in any of our tests. I
> expect that this is because we usually expand trip counts, and
> those are never pointers (anymore). Second, the non-i8 GEP was
> actually incorrect in multiple ways, because it used SCEV type
> sizes, which don't match DL type sizes (for pointers) and certainly
> don't match type alloc sizes (which is what GEPs actually use).
> As such, I'm simplifying the code to always use the i8 GEP code
> path if it does get hit.
>
> Added:
>      
>
> Modified:
>      llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
>
> Removed:
>      
>
>
> ################################################################################
> diff  --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
> index 1495ea1a4088..5363a851fc27 100644
> --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
> +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
> @@ -1981,22 +1981,14 @@ Value *SCEVExpander::expand(const SCEV *S) {
>   
>       if (VO.second) {
>         if (PointerType *Vty = dyn_cast<PointerType>(V->getType())) {
> -        Type *Ety = Vty->getPointerElementType();
>           int64_t Offset = VO.second->getSExtValue();
> -        int64_t ESize = SE.getTypeSizeInBits(Ety);
> -        if ((Offset * 8) % ESize == 0) {
> -          ConstantInt *Idx =
> -            ConstantInt::getSigned(VO.second->getType(), -(Offset * 8) / ESize);
> -          V = Builder.CreateGEP(Ety, V, Idx, "scevgep");
> -        } else {
> -          ConstantInt *Idx =
> -            ConstantInt::getSigned(VO.second->getType(), -Offset);
> -          unsigned AS = Vty->getAddressSpace();
> -          V = Builder.CreateBitCast(V, Type::getInt8PtrTy(SE.getContext(), AS));
> -          V = Builder.CreateGEP(Type::getInt8Ty(SE.getContext()), V, Idx,
> -                                "uglygep");
> -          V = Builder.CreateBitCast(V, Vty);
> -        }
> +        ConstantInt *Idx =
> +          ConstantInt::getSigned(VO.second->getType(), -Offset);
> +        unsigned AS = Vty->getAddressSpace();
> +        V = Builder.CreateBitCast(V, Type::getInt8PtrTy(SE.getContext(), AS));
> +        V = Builder.CreateGEP(Type::getInt8Ty(SE.getContext()), V, Idx,
> +                              "uglygep");
> +        V = Builder.CreateBitCast(V, Vty);
>         } else {
>           V = Builder.CreateSub(V, VO.second);
>         }
>
>
>          
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list