[llvm] [InstCombine] Handle ceil division idiom (PR #100977)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 07:06:06 PDT 2024


nikic wrote:

> > The key one is probably this in DataLayout:
> > ```
> >   TypeSize getTypeStoreSize(Type *Ty) const {
> >     TypeSize BaseSize = getTypeSizeInBits(Ty);
> >     return {divideCeil(BaseSize.getKnownMinValue(), 8), BaseSize.isScalable()};
> >   }
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > This works on uint64_t and nothing tells us that it will not overflow :(
> 
> Would it make sense by any chance to change `divideCeil` to somehow take into account when we know it will not overflow? It seems there are a handful of such cases.

I think a good way to solve this one would be to invert the relationship between getTypeStoreSize and getTypeStoreSizeInBits and use alignToPowerOf2 + plain divide.

https://github.com/llvm/llvm-project/pull/100977


More information about the llvm-commits mailing list