@@ -651,7 +651,7 @@ class NewGVN {
651651 BitVector TouchedInstructions;
652652
653653 DenseMap<const BasicBlock *, std::pair<unsigned , unsigned >> BlockInstRange;
654- mutable DenseMap<const IntrinsicInst *, const Value *> PredicateSwapChoice;
654+ mutable DenseMap<const BitCastInst *, const Value *> PredicateSwapChoice;
655655
656656#ifndef NDEBUG
657657 // Debugging for how many times each block and instruction got processed.
@@ -819,7 +819,7 @@ class NewGVN {
819819 BasicBlock *PHIBlock) const ;
820820 const Expression *performSymbolicAggrValueEvaluation (Instruction *) const ;
821821 ExprResult performSymbolicCmpEvaluation (Instruction *) const ;
822- ExprResult performSymbolicPredicateInfoEvaluation (IntrinsicInst *) const ;
822+ ExprResult performSymbolicPredicateInfoEvaluation (BitCastInst *) const ;
823823
824824 // Congruence finding.
825825 bool someEquivalentDominates (const Instruction *, const Instruction *) const ;
@@ -841,7 +841,7 @@ class NewGVN {
841841 unsigned int getRank (const Value *) const ;
842842 bool shouldSwapOperands (const Value *, const Value *) const ;
843843 bool shouldSwapOperandsForPredicate (const Value *, const Value *,
844- const IntrinsicInst *I) const ;
844+ const BitCastInst *I) const ;
845845
846846 // Reachability handling.
847847 void updateReachableEdge (BasicBlock *, BasicBlock *);
@@ -1013,9 +1013,9 @@ void NewGVN::deleteExpression(const Expression *E) const {
10131013
10141014// If V is a predicateinfo copy, get the thing it is a copy of.
10151015static Value *getCopyOf (const Value *V) {
1016- if (auto *II = dyn_cast<IntrinsicInst >(V))
1017- if (II-> getIntrinsicID () == Intrinsic::ssa_copy )
1018- return II ->getOperand (0 );
1016+ if (auto *BC = dyn_cast<BitCastInst >(V))
1017+ if (BC-> getType () == BC-> getOperand ( 0 )-> getType () )
1018+ return BC ->getOperand (0 );
10191019 return nullptr ;
10201020}
10211021
@@ -1604,7 +1604,7 @@ const Expression *NewGVN::performSymbolicLoadEvaluation(Instruction *I) const {
16041604}
16051605
16061606NewGVN::ExprResult
1607- NewGVN::performSymbolicPredicateInfoEvaluation (IntrinsicInst *I) const {
1607+ NewGVN::performSymbolicPredicateInfoEvaluation (BitCastInst *I) const {
16081608 auto *PI = PredInfo->getPredicateInfoFor (I);
16091609 if (!PI)
16101610 return ExprResult::none ();
@@ -1647,13 +1647,8 @@ NewGVN::performSymbolicPredicateInfoEvaluation(IntrinsicInst *I) const {
16471647NewGVN::ExprResult NewGVN::performSymbolicCallEvaluation (Instruction *I) const {
16481648 auto *CI = cast<CallInst>(I);
16491649 if (auto *II = dyn_cast<IntrinsicInst>(I)) {
1650- // Intrinsics with the returned attribute are copies of arguments.
1651- if (auto *ReturnedValue = II->getReturnedArgOperand ()) {
1652- if (II->getIntrinsicID () == Intrinsic::ssa_copy)
1653- if (auto Res = performSymbolicPredicateInfoEvaluation (II))
1654- return Res;
1650+ if (auto *ReturnedValue = II->getReturnedArgOperand ())
16551651 return ExprResult::some (createVariableOrConstant (ReturnedValue));
1656- }
16571652 }
16581653
16591654 // FIXME: Currently the calls which may access the thread id may
@@ -2032,6 +2027,12 @@ NewGVN::performSymbolicEvaluation(Instruction *I,
20322027 E = performSymbolicLoadEvaluation (I);
20332028 break ;
20342029 case Instruction::BitCast:
2030+ // Intrinsics with the returned attribute are copies of arguments.
2031+ if (I->getType () == I->getOperand (0 )->getType ())
2032+ if (auto Res =
2033+ performSymbolicPredicateInfoEvaluation (cast<BitCastInst>(I)))
2034+ return Res;
2035+ [[fallthrough]];
20352036 case Instruction::AddrSpaceCast:
20362037 case Instruction::Freeze:
20372038 return createExpression (I);
@@ -4075,8 +4076,7 @@ bool NewGVN::eliminateInstructions(Function &F) {
40754076 if (DominatingLeader != Def) {
40764077 // Even if the instruction is removed, we still need to update
40774078 // flags/metadata due to downstreams users of the leader.
4078- if (!match (DefI, m_Intrinsic<Intrinsic::ssa_copy>()))
4079- patchReplacementInstruction (DefI, DominatingLeader);
4079+ patchReplacementInstruction (DefI, DominatingLeader);
40804080
40814081 SmallVector<DbgVariableRecord *> DVRUsers;
40824082 findDbgUsers (DefI, DVRUsers);
@@ -4116,10 +4116,14 @@ bool NewGVN::eliminateInstructions(Function &F) {
41164116
41174117 Value *DominatingLeader = EliminationStack.back ();
41184118
4119- auto *II = dyn_cast<IntrinsicInst>(DominatingLeader);
4120- bool isSSACopy = II && II->getIntrinsicID () == Intrinsic::ssa_copy;
4121- if (isSSACopy)
4122- DominatingLeader = II->getOperand (0 );
4119+ Instruction *SSACopy = nullptr ;
4120+ if (auto *BC = dyn_cast<BitCastInst>(DominatingLeader)) {
4121+ if (BC->getType () == BC->getOperand (0 )->getType () &&
4122+ PredInfo->getPredicateInfoFor (DominatingLeader)) {
4123+ SSACopy = BC;
4124+ DominatingLeader = BC->getOperand (0 );
4125+ }
4126+ }
41234127
41244128 // Don't replace our existing users with ourselves.
41254129 if (U->get () == DominatingLeader)
@@ -4145,12 +4149,12 @@ bool NewGVN::eliminateInstructions(Function &F) {
41454149 ProbablyDead.erase (cast<Instruction>(DominatingLeader));
41464150 // For copy instructions, we use their operand as a leader,
41474151 // which means we remove a user of the copy and it may become dead.
4148- if (isSSACopy ) {
4149- auto It = UseCounts.find (II );
4152+ if (SSACopy ) {
4153+ auto It = UseCounts.find (SSACopy );
41504154 if (It != UseCounts.end ()) {
41514155 unsigned &IIUseCount = It->second ;
41524156 if (--IIUseCount == 0 )
4153- ProbablyDead.insert (II );
4157+ ProbablyDead.insert (SSACopy );
41544158 }
41554159 }
41564160 ++LeaderUseCount;
@@ -4251,7 +4255,7 @@ bool NewGVN::shouldSwapOperands(const Value *A, const Value *B) const {
42514255}
42524256
42534257bool NewGVN::shouldSwapOperandsForPredicate (const Value *A, const Value *B,
4254- const IntrinsicInst *I) const {
4258+ const BitCastInst *I) const {
42554259 if (shouldSwapOperands (A, B)) {
42564260 PredicateSwapChoice[I] = B;
42574261 return true ;
0 commit comments