brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · 157e98f Raw
103 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py2; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s3 4; Tests demonstrate the bug reported as PR48225 by Congzhe Cao.5 6; When %boolcond = false and %cond = 0:7; - %cond.false.on.first.iter is false on 1st iteration;8; - %cond.false.on.second.iter is false on 2nd iteration;9; - Therefore, their AND is false on first two iterations, and the backedge is taken twice.10;  'constant max backedge-taken count is 1' is a bug caused by wrong treatment of AND11;  condition in the computation logic. It should be 2.12define void @test_and(i1 %boolcond) {13; CHECK-LABEL: 'test_and'14; CHECK-NEXT:  Classifying expressions for: @test_and15; CHECK-NEXT:    %conv = zext i1 %boolcond to i3216; CHECK-NEXT:    --> (zext i1 %boolcond to i32) U: [0,2) S: [0,2)17; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]18; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }19; CHECK-NEXT:    %or.cond = and i1 %cond.false.on.first.iter, %cond.false.on.second.iter20; CHECK-NEXT:    --> (%cond.false.on.first.iter umin %cond.false.on.second.iter) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }21; CHECK-NEXT:    %inc = add nuw nsw i32 %iv, 122; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }23; CHECK-NEXT:  Determining loop execution counts for: @test_and24; CHECK-NEXT:  Loop %loop: <multiple exits> Unpredictable backedge-taken count.25; CHECK-NEXT:    exit count for loop: i32 226; CHECK-NEXT:    exit count for backedge: ***COULDNOTCOMPUTE***27; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is i32 228; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is i32 229; CHECK-NEXT:    symbolic max exit count for loop: i32 230; CHECK-NEXT:    symbolic max exit count for backedge: ***COULDNOTCOMPUTE***31;32entry:33  %conv = zext i1 %boolcond to i3234  br label %loop35 36loop:37  %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]38  %cmp = icmp ult i32 %iv, 239  br i1 %cmp, label %backedge, label %for.end40 41backedge:42  %cond.false.on.first.iter = icmp ne i32 %iv, 043  %cond.false.on.second.iter = icmp eq i32 %iv, %conv44  %or.cond = and i1 %cond.false.on.first.iter, %cond.false.on.second.iter45  %inc = add nuw nsw i32 %iv, 146  br i1 %or.cond, label %exit, label %loop47 48exit:49  unreachable50 51for.end:52  ret void53}54 55; When %boolcond = false and %cond = 0:56; - %cond.true.on.first.iter is true on 1st iteration;57; - %cond.true.on.second.iter is true on 2nd iteration;58; - Therefore, their OR is true on first two iterations, and the backedge is taken twice.59;  'constant max backedge-taken count is 1' is a bug caused by wrong treatment of OR60;  condition in the computation logic. It should be 2.61define void @test_or(i1 %boolcond) {62; CHECK-LABEL: 'test_or'63; CHECK-NEXT:  Classifying expressions for: @test_or64; CHECK-NEXT:    %conv = zext i1 %boolcond to i3265; CHECK-NEXT:    --> (zext i1 %boolcond to i32) U: [0,2) S: [0,2)66; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]67; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }68; CHECK-NEXT:    %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter69; CHECK-NEXT:    --> (%cond.true.on.first.iter umax %cond.true.on.second.iter) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }70; CHECK-NEXT:    %inc = add nuw nsw i32 %iv, 171; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }72; CHECK-NEXT:  Determining loop execution counts for: @test_or73; CHECK-NEXT:  Loop %loop: <multiple exits> Unpredictable backedge-taken count.74; CHECK-NEXT:    exit count for loop: i32 275; CHECK-NEXT:    exit count for backedge: ***COULDNOTCOMPUTE***76; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is i32 277; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is i32 278; CHECK-NEXT:    symbolic max exit count for loop: i32 279; CHECK-NEXT:    symbolic max exit count for backedge: ***COULDNOTCOMPUTE***80;81entry:82  %conv = zext i1 %boolcond to i3283  br label %loop84 85loop:86  %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]87  %cmp = icmp ult i32 %iv, 288  br i1 %cmp, label %backedge, label %for.end89 90backedge:91  %cond.true.on.first.iter = icmp eq i32 %iv, 092  %cond.true.on.second.iter = icmp ne i32 %iv, %conv93  %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter94  %inc = add nuw nsw i32 %iv, 195  br i1 %or.cond, label %loop, label %exit96 97exit:98  unreachable99 100for.end:101  ret void102}103