[PATCH] D82061: [IR] Prefer scalar type for struct indexes in GEP constant expressions.
Sander de Smalen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 19 14:42:02 PDT 2020
sdesmalen added inline comments.
================
Comment at: llvm/lib/IR/Constants.cpp:2192
+ !Idx->getType()->isVectorTy()) {
Idx = ConstantVector::getSplat(EltCount, Idx);
+ }
----------------
efriedma wrote:
> sdesmalen wrote:
> > What is the reason for not always using a scalar index value?
> In my thinking, there are two reasons:
>
> 1. I wanted to be conservative; arbitrary constant expressions are legal in this position anyway, so the harm from code failing to understand a vector splat is much smaller.
> 2. We don't want to accidentally change the result type of a GEP if every operand is a splat.
Okay so if I understand that correctly, we can do this change safely for struct types without risking to change the result type. because in e.g.:
```%gep = getelementptr %struct, %struct* null, i32 0, <4 x i32> <i32 1, i32 1, i32 1, i32 1> ```
the `i32 0` will always be expanded into a vector:
```%gep = getelementptr %struct, %struct* null, <4 x i32> zeroinitializer, i32 1```
And so there is always at least one index that will remain a vector (splat).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D82061/new/
https://reviews.llvm.org/D82061
More information about the llvm-commits
mailing list