@@ -4899,13 +4899,14 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
4899
4899
// If operand is guaranteed not to be poison, there is no need to add freeze
4900
4900
// to the operand. So we first find the operand that is not guaranteed to be
4901
4901
// poison.
4902
- Use *MaybePoisonOperand = nullptr ;
4903
- for (Use &U : OrigOpInst->operands ()) {
4904
- if (isa<MetadataAsValue>(U.get ()) ||
4905
- isGuaranteedNotToBeUndefOrPoison (U.get ()))
4902
+ Value *MaybePoisonOperand = nullptr ;
4903
+ for (Value *V : OrigOpInst->operands ()) {
4904
+ if (isa<MetadataAsValue>(V) || isGuaranteedNotToBeUndefOrPoison (V) ||
4905
+ // Treat identical operands as a single operand.
4906
+ (MaybePoisonOperand && MaybePoisonOperand == V))
4906
4907
continue ;
4907
4908
if (!MaybePoisonOperand)
4908
- MaybePoisonOperand = &U ;
4909
+ MaybePoisonOperand = V ;
4909
4910
else
4910
4911
return nullptr ;
4911
4912
}
@@ -4917,10 +4918,10 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
4917
4918
return OrigOp;
4918
4919
4919
4920
Builder.SetInsertPoint (OrigOpInst);
4920
- auto *FrozenMaybePoisonOperand = Builder.CreateFreeze (
4921
- MaybePoisonOperand-> get () , MaybePoisonOperand-> get () ->getName () + " .fr" );
4921
+ Value *FrozenMaybePoisonOperand = Builder.CreateFreeze (
4922
+ MaybePoisonOperand, MaybePoisonOperand->getName () + " .fr" );
4922
4923
4923
- replaceUse (* MaybePoisonOperand, FrozenMaybePoisonOperand);
4924
+ OrigOpInst-> replaceUsesOfWith ( MaybePoisonOperand, FrozenMaybePoisonOperand);
4924
4925
return OrigOp;
4925
4926
}
4926
4927
0 commit comments