brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.9 KiB · e687216 Raw
126 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py2; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s3 4; Tests for smin & smax folds.5 6; Test case from PR1614.7define i32 @test_PR1614(i32 %a, i32 %b, i32 %c) {8; CHECK-LABEL: 'test_PR1614'9; CHECK-NEXT:  Classifying expressions for: @test_PR161410; CHECK-NEXT:    %B = select i1 %A, i32 %a, i32 %b11; CHECK-NEXT:    --> (%a smax %b) U: full-set S: full-set12; CHECK-NEXT:    %D = select i1 %C, i32 %B, i32 %c13; CHECK-NEXT:    --> (%a smax %b smax %c) U: full-set S: full-set14; CHECK-NEXT:  Determining loop execution counts for: @test_PR161415;16 17  %A = icmp sgt i32 %a, %b18  %B = select i1 %A, i32 %a, i32 %b19  %C = icmp sle i32 %c, %B20  %D = select i1 %C, i32 %B, i32 %c21  ret i32 %D22}23 24declare void @iteration()25 26; Test case from PR46939.27; The information from the loop guard can be used to simplify the trip count expression.28define void @smin_simplify_with_guard(i32 %n) {29; CHECK-LABEL: 'smin_simplify_with_guard'30; CHECK-NEXT:  Classifying expressions for: @smin_simplify_with_guard31; CHECK-NEXT:    %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]32; CHECK-NEXT:    --> {%n,+,-1}<nsw><%for.body> U: full-set S: full-set Exits: 0 LoopDispositions: { %for.body: Computable }33; CHECK-NEXT:    %dec = add nsw i32 %i.011, -134; CHECK-NEXT:    --> {(-1 + %n),+,-1}<nw><%for.body> U: full-set S: full-set Exits: -1 LoopDispositions: { %for.body: Computable }35; CHECK-NEXT:  Determining loop execution counts for: @smin_simplify_with_guard36; CHECK-NEXT:  Loop %for.body: backedge-taken count is %n37; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 214748364738; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is %n39; CHECK-NEXT:  Loop %for.body: Trip multiple is 140;41entry:42  %cmp10 = icmp sgt i32 %n, -143  br i1 %cmp10, label %for.body.lr.ph, label %for.cond.cleanup44 45for.body.lr.ph:46  br label %for.body47 48for.body:49  %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]50  call void @iteration()51  %dec = add nsw i32 %i.011, -152  %cmp = icmp sgt i32 %i.011, 053  br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit54 55for.cond.cleanup.loopexit:56  br label %for.cond.cleanup57 58for.cond.cleanup:59  ret void60}61 62define void @smin_to_smax(i32 %n) {63; FIXME: ((-1 * (0 smin %n)) + %n)  is actually just  (0 smax %n)64; CHECK-LABEL: 'smin_to_smax'65; CHECK-NEXT:  Classifying expressions for: @smin_to_smax66; CHECK-NEXT:    %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]67; CHECK-NEXT:    --> {%n,+,-1}<nsw><%for.body> U: full-set S: full-set Exits: (0 smin %n) LoopDispositions: { %for.body: Computable }68; CHECK-NEXT:    %dec = add nsw i32 %i.011, -169; CHECK-NEXT:    --> {(-1 + %n),+,-1}<nw><%for.body> U: full-set S: full-set Exits: (-1 + (0 smin %n)) LoopDispositions: { %for.body: Computable }70; CHECK-NEXT:  Determining loop execution counts for: @smin_to_smax71; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((-1 * (0 smin %n)) + %n)72; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 214748364773; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is ((-1 * (0 smin %n)) + %n)74; CHECK-NEXT:  Loop %for.body: Trip multiple is 175;76entry:77  br label %for.body.lr.ph78 79for.body.lr.ph:80  br label %for.body81 82for.body:83  %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]84  call void @iteration()85  %dec = add nsw i32 %i.011, -186  %cmp = icmp sgt i32 %i.011, 087  br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit88 89for.cond.cleanup.loopexit:90  br label %for.cond.cleanup91 92for.cond.cleanup:93  ret void94}95 96; The information from the loop guard can be used to simplify the trip count expression.97define void @smax_simplify_with_guard(i32 %start, i32 %n) {98; CHECK-LABEL: 'smax_simplify_with_guard'99; CHECK-NEXT:  Classifying expressions for: @smax_simplify_with_guard100; CHECK-NEXT:    %k.0.i26 = phi i32 [ %start, %loop.ph ], [ %inc.i, %loop ]101; CHECK-NEXT:    --> {%start,+,1}<nsw><%loop> U: full-set S: full-set Exits: %n LoopDispositions: { %loop: Computable }102; CHECK-NEXT:    %inc.i = add nsw i32 %k.0.i26, 1103; CHECK-NEXT:    --> {(1 + %start),+,1}<nw><%loop> U: full-set S: full-set Exits: (1 + %n) LoopDispositions: { %loop: Computable }104; CHECK-NEXT:  Determining loop execution counts for: @smax_simplify_with_guard105; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-1 * %start) + %n)106; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is i32 -1107; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is ((-1 * %start) + %n)108; CHECK-NEXT:  Loop %loop: Trip multiple is 1109;110entry:111  %guard = icmp sge i32 %n, %start112  br i1 %guard, label %loop.ph, label %exit113 114loop.ph:115  br label %loop116 117loop:118  %k.0.i26 = phi i32 [ %start, %loop.ph ], [ %inc.i, %loop ]119  %inc.i = add nsw i32 %k.0.i26, 1120  %cmp26.not.i.not = icmp slt i32 %k.0.i26, %n121  br i1 %cmp26.not.i.not, label %loop, label %exit122 123exit:124  ret void125}126