This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyInst] Use correct type for GEPs with vector indices.
ClosedPublic

Authored by fhahn on Apr 6 2021, 8:14 AM.

Details

Summary

The current code does not properly handle vector indices unless they are
the first index.

At the moment LangRef gives the impression that the vector index must be
the one and only index (https://llvm.org/docs/LangRef.html#getelementptr-instruction).

But vector indices can appear at any position and according to the
verifier there may be multiple vector indices. If that's the case, the
number of elements must match.

This patch updates SimplifyGEPInst to properly handle those additional
cases.

Diff Detail

Event Timeline

fhahn created this revision.Apr 6 2021, 8:14 AM
fhahn requested review of this revision.Apr 6 2021, 8:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2021, 8:14 AM
Herald added a subscriber: wdng. · View Herald Transcript
nikic added a comment.Apr 6 2021, 9:06 AM

This looks okay, but I wonder whether we shouldn't be adjusting the getIndexedType() API instead. We have similar code elsewhere, for example in https://github.com/llvm/llvm-project/blob/9c5ebf0358960adf28931569a0c801b56c8008d9/llvm/lib/IR/Constants.cpp#L2415-L2430.

nikic accepted this revision.Apr 6 2021, 9:13 AM

It probably makes sense to land this first in any case, so LGTM.

This revision is now accepted and ready to land.Apr 6 2021, 9:13 AM
fhahn added a comment.Apr 6 2021, 9:51 AM

This looks okay, but I wonder whether we shouldn't be adjusting the getIndexedType() API instead. We have similar code elsewhere, for example in https://github.com/llvm/llvm-project/blob/9c5ebf0358960adf28931569a0c801b56c8008d9/llvm/lib/IR/Constants.cpp#L2415-L2430.

SGTM, I'll look into this as follow-up