brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · ae10ab8 Raw
106 lines · plain
1; RUN: opt -passes='print<access-info>' %s -disable-output 2>&1 | FileCheck %s2 3target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"4 5; i and i + 1 can overflow in the following kernel:6; void test1(unsigned long long x, int *a, int *b) {7;  for (unsigned i = 0; i < x; ++i)8;    b[i] = a[i+1] + 1;9; }10;11; If accesses to a and b can alias, we need to emit a run-time alias check12; between accesses to a and b. However, when i and i + 1 can wrap, their13; SCEV expression is not an AddRec. We need to create SCEV predicates and14; coerce the expressions to AddRecs in order to be able to emit the run-time15; alias check.16;17; The accesses at b[i] and a[i+1] correspond to the addresses %arrayidx and18; %arrayidx4 in the test. The SCEV expressions for these are:19;  ((4 * (zext i32 {1,+,1}<%for.body> to i64))<nuw><nsw> + %a)<nsw>20;  ((4 * (zext i32 {0,+,1}<%for.body> to i64))<nuw><nsw> + %b)<nsw>21;22; The transformed expressions are:23;  i64 {(4 + %a),+,4}<%for.body>24;  i64 {(4 + %b),+,4}<%for.body>25 26; CHECK-LABEL: test127; CHECK:         Memory dependences are safe with run-time checks28; CHECK-NEXT:    Dependences:29; CHECK-NEXT:    Run-time memory checks:30; CHECK-NEXT:    Check 0:31; CHECK-NEXT:      Comparing group32; CHECK-NEXT:        %arrayidx4 = getelementptr inbounds i32, ptr %b, i64 %conv1133; CHECK-NEXT:      Against group34; CHECK-NEXT:        %arrayidx = getelementptr inbounds i32, ptr %a, i64 %idxprom35; CHECK-NEXT:    Grouped accesses:36; CHECK-NEXT:      Group37; CHECK-NEXT:        (Low: %b High: ((4 * (1 umax %x)) + %b))38; CHECK-NEXT:          Member: {%b,+,4}<%for.body>39; CHECK-NEXT:      Group40; CHECK-NEXT:        (Low: (4 + %a) High: (4 + (4 * (1 umax %x)) + %a))41; CHECK-NEXT:          Member: {(4 + %a),+,4}<%for.body>42; CHECK:         Non vectorizable stores to invariant address were not found in loop.43; CHECK-NEXT:    SCEV assumptions:44; CHECK-NEXT:    {1,+,1}<%for.body> Added Flags: <nusw>45; CHECK:         Expressions re-written:46; CHECK-NEXT:    [PSE]  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %idxprom:47; CHECK-NEXT:      ((4 * (zext i32 {1,+,1}<%for.body> to i64))<nuw><nsw> + %a)<nuw>48; CHECK-NEXT:      --> {(4 + %a),+,4}<%for.body>49; CHECK-NEXT:    [PSE]  %arrayidx4 = getelementptr inbounds i32, ptr %b, i64 %conv11:50; CHECK-NEXT:      ((4 * (zext i32 {0,+,1}<%for.body> to i64))<nuw><nsw> + %b)<nuw>51; CHECK-NEXT:      --> {%b,+,4}<%for.body>52define void @test1(i64 %x, ptr %a, ptr %b) {53entry:54  br label %for.body55 56for.body:                                         ; preds = %for.body.preheader, %for.body57  %conv11 = phi i64 [ %conv, %for.body ], [ 0, %entry ]58  %i.010 = phi i32 [ %add, %for.body ], [ 0, %entry ]59  %add = add i32 %i.010, 160  %idxprom = zext i32 %add to i6461  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %idxprom62  %ld = load i32, ptr %arrayidx, align 463  %add2 = add nsw i32 %ld, 164  %arrayidx4 = getelementptr inbounds i32, ptr %b, i64 %conv1165  store i32 %add2, ptr %arrayidx4, align 466  %conv = zext i32 %add to i6467  %cmp = icmp ult i64 %conv, %x68  br i1 %cmp, label %for.body, label %exit69 70exit:71  ret void72}73 74; i can overflow in the following kernel:75; void test2(unsigned long long x, int *a) {76;   for (unsigned i = 0; i < x; ++i)77;     a[i] = a[i] + 1;78; }79;80; We need to check that i doesn't wrap, but we don't need a run-time alias81; check. We also need an extra no-wrap check to get the backedge taken count.82 83; CHECK-LABEL: test284; CHECK: Memory dependences are safe85; CHECK: SCEV assumptions:86; CHECK-NEXT:   {1,+,1}<%for.body> Added Flags: <nusw>87 define void @test2(i64 %x, ptr %a) {88entry:89  br label %for.body90 91for.body:92  %conv11 = phi i64 [ %conv, %for.body ], [ 0, %entry ]93  %i.010 = phi i32 [ %inc, %for.body ], [ 0, %entry ]94  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %conv1195  %ld = load i32, ptr %arrayidx, align 496  %add = add nsw i32 %ld, 197  store i32 %add, ptr %arrayidx, align 498  %inc = add i32 %i.010, 199  %conv = zext i32 %inc to i64100  %cmp = icmp ult i64 %conv, %x101  br i1 %cmp, label %for.body, label %exit102 103exit:104  ret void105}106