llvm.org GIT mirror llvm / f6d994c
[RuntimeUnrolling] Populate the VMap entry correctly when default generated through lookup During runtime unrolling on loops with multiple exits, we update the exit blocks with the correct phi values from both original and remainder loop. In this process, we lookup the VMap for the mapped incoming phi values, but did not update the VMap if a default entry was generated in the VMap during the lookup. This default value is generated when constants or values outside the current loop are looked up. This patch fixes the assertion failure when null entries are present in the VMap because of this lookup. Added a testcase that showcases the problem. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313358 91177308-0d34-0410-b5e6-96231b3b80d8 Anna Thomas 2 years ago
2 changed file(s) with 51 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
781781 // Add the incoming values from the remainder code to the end of the phi
782782 // node.
783783 for (unsigned i =0; i < oldNumOperands; i++){
784 Value *newVal = VMap[Phi->getIncomingValue(i)];
784 Value *newVal = VMap.lookup(Phi->getIncomingValue(i));
785785 // newVal can be a constant or derived from values outside the loop, and
786 // hence need not have a VMap value.
787 if (!newVal)
786 // hence need not have a VMap value. Also, since lookup already generated
787 // a default "null" VMap entry for this value, we need to populate that
788 // VMap entry correctly, with the mapped entry being itself.
789 if (!newVal) {
788790 newVal = Phi->getIncomingValue(i);
791 VMap[Phi->getIncomingValue(i)] = Phi->getIncomingValue(i);
792 }
789793 Phi->addIncoming(newVal,
790794 cast(VMap[Phi->getIncomingBlock(i)]));
791795 }
22 ; RUN: opt < %s -loop-unroll -unroll-runtime -unroll-count=2 -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-dom-info -verify-loop-info -instcombine
33 ; RUN: opt < %s -loop-unroll -unroll-runtime=true -unroll-runtime-epilog=false -unroll-runtime-multi-exit=true -verify-dom-info -verify-loop-info -instcombine -S | FileCheck %s -check-prefix=PROLOG
44 ; RUN: opt < %s -loop-unroll -unroll-runtime -unroll-runtime-epilog=false -unroll-count=2 -unroll-runtime-multi-exit=true -verify-dom-info -verify-loop-info -instcombine
5
6 ; REQUIRES: asserts
57
68 ; the third and fifth RUNs generate an epilog/prolog remainder block for all the test
79 ; cases below (it does not generate a loop).
477479 exit: ; preds = %latch
478480 ret void
479481 }
482
483 declare i8 addrspace(1)* @foo(i32)
484 ; inner loop prolog unrolled
485 ; a value from outer loop is used in exit block of inner loop.
486 ; Don't create VMap entries for such values (%trip).
487 define i8 addrspace(1)* @test9(i8* nocapture readonly %arg, i32 %n) {
488 ; PROLOG: test9(
489 ; PROLOG: header.prol:
490 ; PROLOG-NEXT: %phi.prol = phi i64 [ 0, %header.prol.preheader ], [ %iv.next.prol, %latch.prol ]
491 ; PROLOG: latch.prol:
492 ; PROLOG-NOT: trip
493 ; PROLOG: br i1 %prol.iter.cmp, label %header.prol.loopexit.unr-lcssa, label %header.prol
494 bb:
495 br label %outerloopHdr
496
497 outerloopHdr: ; preds = %outerLatch, %bb
498 %trip = add i32 %n, -1
499 %outercnd = icmp slt i32 0, %trip
500 br i1 %outercnd, label %preheader, label %outerLatch
501
502 preheader: ; preds = %outerloopHdr
503 %tmp4 = zext i32 0 to i64
504 br label %header
505
506 header: ; preds = %latch, %preheader
507 %phi = phi i64 [ %tmp4, %preheader ], [ %iv.next, %latch ]
508 %tmp7 = trunc i64 %phi to i32
509 br i1 true, label %latch, label %innerexit
510
511 innerexit: ; preds = %header
512 %tmp9 = call i8 addrspace(1)* @foo(i32 %trip)
513 ret i8 addrspace(1)* %tmp9
514
515 latch: ; preds = %header
516 %tmp11 = add nsw i32 %tmp7, 1
517 %innercnd = icmp slt i32 %tmp11, %trip
518 %iv.next = add nuw nsw i64 %phi, 1
519 br i1 %innercnd, label %header, label %outerLatch
520
521 outerLatch: ; preds = %latch, %outerloopHdr
522 br label %outerloopHdr
523 }