[PATCH] D98058: [InstCombine] Simplify phis with incoming pointer-casts.
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 05:59:14 PST 2021
lebedev.ri added a comment.
This indeed won't really work with `foldPHIArgOpIntoPHI()`, first because we actually don't create a new PHI,
secondly, this transform does not use-count restrictions, while `foldPHIArgOpIntoPHI()` has some.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp:1322-1328
+ Value *Inc0 = PN.getIncomingValue(0);
+ Value *Inc0Stripped = Inc0->stripPointerCasts();
+ if (Inc0 != Inc0Stripped &&
+ all_of(PN.incoming_values(), [Inc0, Inc0Stripped](Value *Inc) {
+ return Inc0 == Inc || Inc0Stripped == Inc->stripPointerCasts();
+ })) {
+ return CastInst::CreatePointerCast(Inc0Stripped, PN.getType());
----------------
I would recommend `s/Inc/IV/`
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp:1325-1327
+ all_of(PN.incoming_values(), [Inc0, Inc0Stripped](Value *Inc) {
+ return Inc0 == Inc || Inc0Stripped == Inc->stripPointerCasts();
+ })) {
----------------
I would recommend a less brute-force approach.
Add a map<IV, stripped>, and don't redo the work if the result is known.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98058/new/
https://reviews.llvm.org/D98058
More information about the llvm-commits
mailing list