72 lines · plain
1; RUN: opt < %s -S -passes='print<scalar-evolution>,loop-unroll<peeling;full-unroll-max=0>,print<scalar-evolution>' 2>&1 | FileCheck %s2;3; This test ensures that (extractvalue 0 (with-overflow-inst op0, op1))4; is invalidated by LoopPeel when the operands of with-overflow-inst5; are changed.6;7; In the following case, LoopPeel modifies the CFG into another one8; with %bb7 not dominating %bb2 and %bb3 although %extractvalue is9; still the step for the %bb3 loop. %call has been modified and uses10; different operands but the SCEV value for %extractvalue has not been11; invalidated and still refers to %load in its SCEV operands12; (SCEV(%extractvalue) := -2 + -2 * %load).13;14; When LoopUnroll tries to compute the SCEV for the %bb3 Phi, the15; stale data for %extractvalue is used whereas %load is not available16; in %bb3 which is wrong.17;18; for more details and nice pictures: https://github.com/llvm/llvm-project/issues/9758619;20; Although the reason for the bug was in forgetValue, it is still relevant to21; test if LoopPeel invalidates %extractvalue after changing %call.22;23; forgetValue only walks the users, so calling it on the IV Phis does not24; invalidate %extractvalue (thus forgetLoop does not invalidate it too).25; It has to be done by LoopPeel itself.26 27 28define void @loop_peeling_smul_with_overflow() {29; before loop-unroll30; CHECK: Classifying expressions for: @loop_peeling_smul_with_overflow31; CHECK: %extractvalue = extractvalue { i32, i1 } %call, 032; CHECK-NEXT: --> (-2 + (-2 * %load))33; CHECK: %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]34; CHECK-NEXT: --> {0,+,(-2 + (-2 * %load))}<nuw><nsw><%bb3>35; after loop-unroll36; CHECK: Classifying expressions for: @loop_peeling_smul_with_overflow37; CHECK: %extractvalue = extractvalue { i32, i1 } %call, 038; CHECK-NEXT: --> (-2 * %add8.lcssa)39; CHECK: %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]40; CHECK-NEXT: --> {0,+,(-2 * %add8.lcssa)}<nuw><nsw><%bb3>41;42bb:43 br label %bb144 45bb1: ; preds = %bb3, %bb46 %phi = phi i32 [ 0, %bb ], [ %phi4, %bb3 ]47 br label %bb548 49bb2: ; preds = %bb750 %call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8, i32 -2)51 %extractvalue = extractvalue { i32, i1 } %call, 052 br label %bb353 54bb3: ; preds = %bb3, %bb255 %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]56 %add = add i32 %extractvalue, %phi457 br i1 false, label %bb3, label %bb158 59bb5: ; preds = %bb7, %bb160 %phi6 = phi i32 [ 1, %bb1 ], [ 0, %bb7 ]61 %icmp = icmp eq i32 %phi, 062 br i1 %icmp, label %bb9, label %bb763 64bb7: ; preds = %bb565 %load = load i32, ptr addrspace(1) null, align 466 %add8 = add i32 %load, 167 br i1 false, label %bb2, label %bb568 69bb9: ; preds = %bb570 ret void71}72