Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 6969fd1

Browse files
committed
[PeepholeOptimizer] Look through PHIs to find additional register sources
Reapply 243271 with more fixes; although we are not handling multiple sources with coalescable copies, we were not properly skipping this case. - Teaches the ValueTracker in the PeepholeOptimizer to look through PHI instructions. - Add findNextSourceAndRewritePHI method to lookup into multiple sources returnted by the ValueTracker and rewrite PHIs with new sources. With these changes we can find more register sources and rewrite more copies to allow coaslescing of bitcast instructions. Hence, we eliminate unnecessary VR64 <-> GR64 copies in x86, but it could be extended to other archs by marking "isBitcast" on target specific instructions. The x86 example follows: A: psllq %mm1, %mm0 movd %mm0, %r9 jmp C B: por %mm1, %mm0 movd %mm0, %r9 jmp C C: movd %r9, %mm0 pshufw $238, %mm0, %mm0 Becomes: A: psllq %mm1, %mm0 jmp C B: por %mm1, %mm0 jmp C C: pshufw $238, %mm0, %mm0 Differential Revision: http://reviews.llvm.org/D11197 rdar://problem/20404526 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243486 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a0b4070 commit 6969fd1

File tree

4 files changed

+398
-83
lines changed

4 files changed

+398
-83
lines changed

include/llvm/Target/TargetInstrInfo.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,33 @@ class TargetInstrInfo : public MCInstrInfo {
12661266
unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
12671267
};
12681268

1269+
/// \brief Provide DenseMapInfo for TargetInstrInfo::RegSubRegPair.
1270+
template<>
1271+
struct DenseMapInfo<TargetInstrInfo::RegSubRegPair> {
1272+
typedef DenseMapInfo<unsigned> RegInfo;
1273+
1274+
static inline TargetInstrInfo::RegSubRegPair getEmptyKey() {
1275+
return TargetInstrInfo::RegSubRegPair(RegInfo::getEmptyKey(),
1276+
RegInfo::getEmptyKey());
1277+
}
1278+
static inline TargetInstrInfo::RegSubRegPair getTombstoneKey() {
1279+
return TargetInstrInfo::RegSubRegPair(RegInfo::getTombstoneKey(),
1280+
RegInfo::getTombstoneKey());
1281+
}
1282+
/// \brief Reuse getHashValue implementation from
1283+
/// std::pair<unsigned, unsigned>.
1284+
static unsigned getHashValue(const TargetInstrInfo::RegSubRegPair &Val) {
1285+
std::pair<unsigned, unsigned> PairVal =
1286+
std::make_pair(Val.Reg, Val.SubReg);
1287+
return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
1288+
}
1289+
static bool isEqual(const TargetInstrInfo::RegSubRegPair &LHS,
1290+
const TargetInstrInfo::RegSubRegPair &RHS) {
1291+
return RegInfo::isEqual(LHS.Reg, RHS.Reg) &&
1292+
RegInfo::isEqual(LHS.SubReg, RHS.SubReg);
1293+
}
1294+
};
1295+
12691296
} // End llvm namespace
12701297

12711298
#endif

0 commit comments

Comments
 (0)