This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Stop folding inttoptr+bitcast if multiple uses
AbandonedPublic

Authored by ruiling on Mar 21 2021, 11:07 PM.

Details

Summary

Don't combine a inttoptr followed by a bitcast to another pointer type if
the intermediate pointer has multiple uses. Such combine is very unfriendly
to later passes like ScalarEvolutionAnalysis and LoadStoreVectorizer. For
example, this may change the IR from:

%p1 = inttoptr %addr to i32 *
%i  = load i32, i32 * %p1

==> %p2 = bitcast i32 * %p1 to float *

%p3 = getelementptr float, float * %p2, i64 1
%f  = load float, float * %p3

into:

%p1 = inttoptr %addr to i32 *

==> %p2 = inttoptr %addr to float *

%i  = load i32, i32 * %p1
%p3 = getelementptr float, float * %p2, i64 1
%f  = load float, float * %p3

This causes above mentioned passes fail to reason that the two pointers
are consecutive, thus fail to vectorize the two loads.

Diff Detail

Event Timeline

ruiling created this revision.Mar 21 2021, 11:07 PM
ruiling requested review of this revision.Mar 21 2021, 11:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2021, 11:07 PM
arsenm added inline comments.Mar 22 2021, 11:27 AM
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
279

Remove the spaces between the type and * throughout the comment

295–296

This feels like the wrong place. This is isEliminableCastPair, and the cast can be eliminated. Can the hasOneUse check go to some specific combine?

i agree that it makes sense, but this is only a partial solution.
I'm looking at the full solution, not sure what fallout it will have yet.

This revision now requires changes to proceed.Mar 22 2021, 3:18 PM
foad added a subscriber: foad.Apr 7 2021, 1:55 AM
Matt added a subscriber: Matt.May 12 2021, 8:41 AM
ruiling abandoned this revision.Nov 7 2021, 10:45 PM