@@ -945,6 +945,18 @@ bool StoreExpression::equals(const Expression &Other) const {
945945 return true ;
946946}
947947
948+ bool CallExpression::equals (const Expression &Other) const {
949+ if (!MemoryExpression::equals (Other))
950+ return false ;
951+
952+ if (auto *RHS = dyn_cast<CallExpression>(&Other))
953+ return Call->getAttributes ()
954+ .intersectWith (Call->getContext (), RHS->Call ->getAttributes ())
955+ .has_value ();
956+
957+ return false ;
958+ }
959+
948960// Determine if the edge From->To is a backedge
949961bool NewGVN::isBackedge (BasicBlock *From, BasicBlock *To) const {
950962 return From == To ||
@@ -3854,16 +3866,6 @@ Value *NewGVN::findPHIOfOpsLeader(const Expression *E,
38543866 return nullptr ;
38553867}
38563868
3857- // Return true iff V1 can be replaced with V2.
3858- static bool canBeReplacedBy (Value *V1, Value *V2) {
3859- if (auto *CB1 = dyn_cast<CallBase>(V1))
3860- if (auto *CB2 = dyn_cast<CallBase>(V2))
3861- return CB1->getAttributes ()
3862- .intersectWith (CB2->getContext (), CB2->getAttributes ())
3863- .has_value ();
3864- return true ;
3865- }
3866-
38673869bool NewGVN::eliminateInstructions (Function &F) {
38683870 // This is a non-standard eliminator. The normal way to eliminate is
38693871 // to walk the dominator tree in order, keeping track of available
@@ -3973,8 +3975,6 @@ bool NewGVN::eliminateInstructions(Function &F) {
39733975 MembersLeft.insert (Member);
39743976 continue ;
39753977 }
3976- if (!canBeReplacedBy (Member, Leader))
3977- continue ;
39783978
39793979 LLVM_DEBUG (dbgs () << " Found replacement " << *(Leader) << " for "
39803980 << *Member << " \n " );
@@ -4082,11 +4082,8 @@ bool NewGVN::eliminateInstructions(Function &F) {
40824082 if (DominatingLeader != Def) {
40834083 // Even if the instruction is removed, we still need to update
40844084 // flags/metadata due to downstreams users of the leader.
4085- if (!match (DefI, m_Intrinsic<Intrinsic::ssa_copy>())) {
4086- if (!canBeReplacedBy (DefI, DominatingLeader))
4087- continue ;
4085+ if (!match (DefI, m_Intrinsic<Intrinsic::ssa_copy>()))
40884086 patchReplacementInstruction (DefI, DominatingLeader);
4089- }
40904087
40914088 markInstructionForDeletion (DefI);
40924089 }
@@ -4134,11 +4131,8 @@ bool NewGVN::eliminateInstructions(Function &F) {
41344131 // original operand, as we already know we can just drop it.
41354132 auto *ReplacedInst = cast<Instruction>(U->get ());
41364133 auto *PI = PredInfo->getPredicateInfoFor (ReplacedInst);
4137- if (!PI || DominatingLeader != PI->OriginalOp ) {
4138- if (!canBeReplacedBy (ReplacedInst, DominatingLeader))
4139- continue ;
4134+ if (!PI || DominatingLeader != PI->OriginalOp )
41404135 patchReplacementInstruction (ReplacedInst, DominatingLeader);
4141- }
41424136
41434137 LLVM_DEBUG (dbgs ()
41444138 << " Found replacement " << *DominatingLeader << " for "
0 commit comments