@@ -241,11 +241,11 @@ class FunctionComparator {
241
241
// / look at their particular properties (bit-width for vectors, and
242
242
// / address space for pointers).
243
243
// / If these properties are equal - compare their contents.
244
- int cmpConstants (const Constant *L, const Constant *R);
244
+ int cmpConstants (const Constant *L, const Constant *R) const ;
245
245
246
246
// / Compares two global values by number. Uses the GlobalNumbersState to
247
247
// / identify the same globals across function calls.
248
- int cmpGlobalValues (GlobalValue *L, GlobalValue *R);
248
+ int cmpGlobalValues (GlobalValue *L, GlobalValue *R) const ;
249
249
250
250
// / Assign or look up previously assigned numbers for the two values, and
251
251
// / return whether the numbers are equal. Numbers are assigned in the order
@@ -265,7 +265,7 @@ class FunctionComparator {
265
265
// / then left value is greater.
266
266
// / In another words, we compare serial numbers, for more details
267
267
// / see comments for sn_mapL and sn_mapR.
268
- int cmpValues (const Value *L, const Value *R);
268
+ int cmpValues (const Value *L, const Value *R) const ;
269
269
270
270
// / Compare two Instructions for equivalence, similar to
271
271
// / Instruction::isSameOperationAs but with modifications to the type
@@ -395,7 +395,7 @@ class FunctionComparator {
395
395
// / But, we are still not able to compare operands of PHI nodes, since those
396
396
// / could be operands from further BBs we didn't scan yet.
397
397
// / So it's impossible to use dominance properties in general.
398
- DenseMap<const Value*, int > sn_mapL, sn_mapR;
398
+ mutable DenseMap<const Value *, int > sn_mapL, sn_mapR;
399
399
400
400
// The global state we will use
401
401
GlobalNumberState* GlobalNumbers;
@@ -528,7 +528,8 @@ int FunctionComparator::cmpOperandBundlesSchema(const Instruction *L,
528
528
// / type.
529
529
// / 2. Compare constant contents.
530
530
// / For more details see declaration comments.
531
- int FunctionComparator::cmpConstants (const Constant *L, const Constant *R) {
531
+ int FunctionComparator::cmpConstants (const Constant *L,
532
+ const Constant *R) const {
532
533
533
534
Type *TyL = L->getType ();
534
535
Type *TyR = R->getType ();
@@ -725,7 +726,7 @@ int FunctionComparator::cmpConstants(const Constant *L, const Constant *R) {
725
726
}
726
727
}
727
728
728
- int FunctionComparator::cmpGlobalValues (GlobalValue *L, GlobalValue* R) {
729
+ int FunctionComparator::cmpGlobalValues (GlobalValue *L, GlobalValue *R) const {
729
730
return cmpNumbers (GlobalNumbers->getNumber (L), GlobalNumbers->getNumber (R));
730
731
}
731
732
@@ -975,6 +976,17 @@ int FunctionComparator::cmpOperations(const Instruction *L,
975
976
return cmpNumbers (RMWI->getSynchScope (),
976
977
cast<AtomicRMWInst>(R)->getSynchScope ());
977
978
}
979
+ if (const PHINode *PNL = dyn_cast<PHINode>(L)) {
980
+ const PHINode *PNR = cast<PHINode>(R);
981
+ // Ensure that in addition to the incoming values being identical
982
+ // (checked by the caller of this function), the incoming blocks
983
+ // are also identical.
984
+ for (unsigned i = 0 , e = PNL->getNumIncomingValues (); i != e; ++i) {
985
+ if (int Res =
986
+ cmpValues (PNL->getIncomingBlock (i), PNR->getIncomingBlock (i)))
987
+ return Res;
988
+ }
989
+ }
978
990
return 0 ;
979
991
}
980
992
@@ -1038,7 +1050,7 @@ int FunctionComparator::cmpInlineAsm(const InlineAsm *L,
1038
1050
// / this is the first time the values are seen, they're added to the mapping so
1039
1051
// / that we will detect mismatches on next use.
1040
1052
// / See comments in declaration for more details.
1041
- int FunctionComparator::cmpValues (const Value *L, const Value *R) {
1053
+ int FunctionComparator::cmpValues (const Value *L, const Value *R) const {
1042
1054
// Catch self-reference case.
1043
1055
if (L == FnL) {
1044
1056
if (R == FnR)
0 commit comments