llvm.org GIT mirror llvm / 1d6610a
NewGVN: Fix PR 34473, by not using ExactlyEqualsExpression for finding phi of ops users. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314612 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Berlin 2 years ago
2 changed file(s) with 64 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
22482248 // For a given expression, mark the phi of ops instructions that could have
22492249 // changed as a result.
22502250 void NewGVN::markPhiOfOpsChanged(const Expression *E) {
2251 touchAndErase(ExpressionToPhiOfOps, ExactEqualsExpression(*E));
2251 touchAndErase(ExpressionToPhiOfOps, E);
22522252 }
22532253
22542254 // Perform congruence finding on a given value numbering expression.
26672667 if (!DebugCounter::shouldExecute(PHIOfOpsCounter))
26682668 return nullptr;
26692669 SmallVector Ops;
2670 SmallPtrSet Deps;
26702671 auto *PHIBlock = getBlockForValue(OpPHI);
26712672 RevisitOnReachabilityChange[PHIBlock].reset(InstrToDFSNum(I));
26722673 for (unsigned PredNum = 0; PredNum < OpPHI->getNumOperands(); ++PredNum) {
26852686 for (auto &Op : ValueOp->operands()) {
26862687 auto *OrigOp = &*Op;
26872688 // When these operand changes, it could change whether there is a
2688 // leader for us or not, so we have to add additional users
2689 // leader for us or not, so we have to add additional users.
26892690 if (isa(Op)) {
26902691 Op = Op->DoPHITranslation(PHIBlock, PredBB);
26912692 if (Op != OrigOp && Op != I)
2692 addAdditionalUsers(Op, I);
2693 Deps.insert(Op);
26932694 } else if (auto *ValuePHI = RealToTemp.lookup(Op)) {
26942695 if (getBlockForValue(ValuePHI) == PHIBlock)
26952696 Op = ValuePHI->getIncomingValue(PredNum);
26962697 }
2697 // When this operand changes, it could change whether there is a
2698 // leader for us or not.
2699 addAdditionalUsers(Op, I);
27002698 // If we phi-translated the op, it must be safe.
27012699 SafeForPHIOfOps = SafeForPHIOfOps &&
27022700 (Op != OrigOp ||
27252723 DEBUG(dbgs() << "Found phi of ops operand " << *FoundVal << " in "
27262724 << getBlockName(PredBB) << "\n");
27272725 }
2726 for (auto Dep : Deps)
2727 addAdditionalUsers(Dep, I);
27282728 sortPHIOps(Ops);
27292729 auto *E = performSymbolicPHIEvaluation(Ops, I, PHIBlock);
27302730 if (isa(E) || isa(E)) {
544544 bb8: ; preds = %bb
545545 ret void
546546 }
547
548 ;; Make sure we reprocess phi of ops involving loads when loads change class.
549 ;; This is PR 34473
550 define void @test13() {
551 ; CHECK-LABEL: @test13(
552 ; CHECK-NEXT: bb:
553 ; CHECK-NEXT: br label [[BB1:%.*]]
554 ; CHECK: bb1:
555 ; CHECK-NEXT: [[TMP:%.*]] = load i8, i8* null
556 ; CHECK-NEXT: br label [[BB3:%.*]]
557 ; CHECK: bb3:
558 ; CHECK-NEXT: [[PHIOFOPS:%.*]] = phi i8 [ [[TMP]], [[BB1]] ], [ [[TMP10:%.*]], [[BB3]] ]
559 ; CHECK-NEXT: [[TMP4:%.*]] = phi i8* [ null, [[BB1]] ], [ [[TMP6:%.*]], [[BB3]] ]
560 ; CHECK-NEXT: [[TMP5:%.*]] = phi i32 [ undef, [[BB1]] ], [ [[TMP9:%.*]], [[BB3]] ]
561 ; CHECK-NEXT: [[TMP6]] = getelementptr i8, i8* [[TMP4]], i64 1
562 ; CHECK-NEXT: [[TMP8:%.*]] = sext i8 [[PHIOFOPS]] to i32
563 ; CHECK-NEXT: [[TMP9]] = mul i32 [[TMP5]], [[TMP8]]
564 ; CHECK-NEXT: [[TMP10]] = load i8, i8* [[TMP6]]
565 ; CHECK-NEXT: [[TMP11:%.*]] = icmp eq i8 [[TMP10]], 0
566 ; CHECK-NEXT: br i1 [[TMP11]], label [[BB12:%.*]], label [[BB3]]
567 ; CHECK: bb12:
568 ; CHECK-NEXT: [[TMP14:%.*]] = icmp eq i32 [[TMP9]], 0
569 ; CHECK-NEXT: br i1 [[TMP14]], label [[BB1]], label [[BB15:%.*]]
570 ; CHECK: bb15:
571 ; CHECK-NEXT: call void (...) @bar()
572 ; CHECK-NEXT: br label [[BB1]]
573 ;
574 bb:
575 br label %bb1
576
577 bb1: ; preds = %bb15, %bb12, %bb
578 %tmp = load i8, i8* null
579 %tmp2 = icmp eq i8 %tmp, 8
580 br label %bb3
581
582 bb3: ; preds = %bb3, %bb1
583 %tmp4 = phi i8* [ null, %bb1 ], [ %tmp6, %bb3 ]
584 %tmp5 = phi i32 [ undef, %bb1 ], [ %tmp9, %bb3 ]
585 %tmp6 = getelementptr i8, i8* %tmp4, i64 1
586 %tmp7 = load i8, i8* %tmp4
587 %tmp8 = sext i8 %tmp7 to i32
588 %tmp9 = mul i32 %tmp5, %tmp8
589 %tmp10 = load i8, i8* %tmp6
590 %tmp11 = icmp eq i8 %tmp10, 0
591 br i1 %tmp11, label %bb12, label %bb3
592
593 bb12: ; preds = %bb3
594 %tmp13 = phi i32 [ %tmp9, %bb3 ]
595 %tmp14 = icmp eq i32 %tmp13, 0
596 br i1 %tmp14, label %bb1, label %bb15
597
598 bb15: ; preds = %bb12
599 call void (...) @bar()
600 br label %bb1
601 }
602
603 declare void @bar(...)
604