1; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s 2; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s --check-prefix=IR 3; 4; Check that we guard the divisions because we moved them and thereby increased 5; their domain. 6; 7; CHECK: Invalid Context: 8; CHECK-NEXT: [p_0] -> { : false } 9; CHECK-NEXT: p0: (((zext i32 %a to i64) /u (zext i32 %b to i64)) /u ((zext i32 %c to i64) /u (zext i32 %d to i64))) 10; 11; void f(unsigned *A, unsigned a, unsigned b, unsigned c, unsigned d) { 12; for (unsigned i; i < 100; i++) 13; A[i] += A[(a / b) / (c / d)]; 14; } 15; 16; IR: %[[A:[.a-zA-Z0-9]*]] = zext i32 %a to i64 17; IR-NEXT: %[[B:[.a-zA-Z0-9]*]] = zext i32 %b to i64 18; IR-NEXT: %[[R0:[.a-zA-Z0-9]*]] = icmp ugt i64 %[[B]], 1 19; IR-NEXT: %[[R1:[.a-zA-Z0-9]*]] = select i1 %[[R0]], i64 %[[B]], i64 1 20; IR-NEXT: %[[R2:[.a-zA-Z0-9]*]] = udiv i64 %[[A]], %[[R1]] 21; IR-NEXT: %[[C:[.a-zA-Z0-9]*]] = zext i32 %c to i64 22; IR-NEXT: %[[D:[.a-zA-Z0-9]*]] = zext i32 %d to i64 23; IR-NEXT: %[[R5:[.a-zA-Z0-9]*]] = icmp ugt i64 %[[D]], 1 24; IR-NEXT: %[[R6:[.a-zA-Z0-9]*]] = select i1 %[[R5]], i64 %[[D]], i64 1 25; IR-NEXT: %[[R7:[.a-zA-Z0-9]*]] = udiv i64 %[[C]], %[[R6]] 26; IR-NEXT: %[[R3:[.a-zA-Z0-9]*]] = icmp ugt i64 %[[R7]], 1 27; IR-NEXT: %[[R4:[.a-zA-Z0-9]*]] = select i1 %[[R3]], i64 %[[R7]], i64 1 28; IR-NEXT: %[[R8:[.a-zA-Z0-9]*]] = udiv i64 %[[R2]], %[[R4]] 29; 30target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 31 32define void @f(i32* %A, i32 %a, i32 %b, i32 %c, i32 %d) { 33entry: 34 br label %for.cond 35 36for.cond: ; preds = %for.inc, %entry 37 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 38 %cmp = icmp ult i64 %indvars.iv, 100 39 br i1 %cmp, label %for.body, label %for.end 40 41for.body: ; preds = %for.cond 42 %div = udiv i32 %a, %b 43 %div1 = udiv i32 %c, %d 44 %div2 = udiv i32 %div, %div1 45 %idxprom = zext i32 %div2 to i64 46 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom 47 %tmp = load i32, i32* %arrayidx, align 4 48 %arrayidx4 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv 49 %tmp1 = load i32, i32* %arrayidx4, align 4 50 %add = add i32 %tmp1, %tmp 51 store i32 %add, i32* %arrayidx4, align 4 52 br label %for.inc 53 54for.inc: ; preds = %for.body 55 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 56 br label %for.cond 57 58for.end: ; preds = %for.cond 59 ret void 60} 61