diff options
| author | John McCall <rjmccall@apple.com> | 2011-06-25 01:32:37 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2011-06-25 01:32:37 +0000 |
| commit | 77527a8e652e3cef5887db8923743c9f89950234 (patch) | |
| tree | 4c7ad96bbc4876b79fdb447876ee7509fbfd93bd /clang/test | |
| parent | c15b0cfc1f89cb8d9779189892d733e2d23d8866 (diff) | |
| download | bcm5719-llvm-77527a8e652e3cef5887db8923743c9f89950234.tar.gz bcm5719-llvm-77527a8e652e3cef5887db8923743c9f89950234.zip | |
Mark the multiply which occurs as part of performing pointer
arithmetic on a VLA as 'nsw', per discussion with djg, and
implement pointer arithmetic (other than array accesses) and
pointer subtraction for VLA types.
llvm-svn: 133855
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/CodeGen/vla.c | 45 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/vla.cpp | 4 |
2 files changed, 46 insertions, 3 deletions
diff --git a/clang/test/CodeGen/vla.c b/clang/test/CodeGen/vla.c index f7cba25d934..c9612bc1603 100644 --- a/clang/test/CodeGen/vla.c +++ b/clang/test/CodeGen/vla.c @@ -94,7 +94,7 @@ double test_PR8567(int n, double (*p)[n][5]) { // CHECK-NEXT: store // CHECK-NEXT: [[N:%.*]] = load i32* [[NV]], align 4 // CHECK-NEXT: [[P:%.*]] = load [5 x double]** [[PV]], align 4 - // CHECK-NEXT: [[T0:%.*]] = mul i32 1, [[N]] + // CHECK-NEXT: [[T0:%.*]] = mul nsw i32 1, [[N]] // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [5 x double]* [[P]], i32 [[T0]] // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds [5 x double]* [[T1]], i32 2 // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [5 x double]* [[T2]], i32 0, i32 3 @@ -102,3 +102,46 @@ double test_PR8567(int n, double (*p)[n][5]) { // CHECK-NEXT: ret double [[T4]] return p[1][2][3]; } + +int test4(unsigned n, char (*p)[n][n+1][6]) { + // CHECK: define i32 @test4( + // CHECK: [[N:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[P:%.*]] = alloca [6 x i8]*, align 4 + // CHECK-NEXT: [[P2:%.*]] = alloca [6 x i8]*, align 4 + // CHECK-NEXT: store i32 + // CHECK-NEXT: store [6 x i8]* + + // VLA captures. + // CHECK-NEXT: [[DIM0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[DIM1:%.*]] = add i32 [[T0]], 1 + + // __typeof. FIXME: does this really need to be loaded? + // CHECK-NEXT: load [6 x i8]** [[P]] + + // CHECK-NEXT: [[T0:%.*]] = load [6 x i8]** [[P]], align 4 + // CHECK-NEXT: [[T1:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[T2:%.*]] = udiv i32 [[T1]], 2 + // CHECK-NEXT: [[T3:%.*]] = mul nuw i32 [[DIM0]], [[DIM1]] + // CHECK-NEXT: [[T4:%.*]] = mul nsw i32 [[T2]], [[T3]] + // CHECK-NEXT: [[T5:%.*]] = getelementptr inbounds [6 x i8]* [[T0]], i32 [[T4]] + // CHECK-NEXT: [[T6:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[T7:%.*]] = udiv i32 [[T6]], 4 + // CHECK-NEXT: [[T8:%.*]] = sub i32 0, [[T7]] + // CHECK-NEXT: [[T9:%.*]] = mul nuw i32 [[DIM0]], [[DIM1]] + // CHECK-NEXT: [[T10:%.*]] = mul nsw i32 [[T8]], [[T9]] + // CHECK-NEXT: [[T11:%.*]] = getelementptr inbounds [6 x i8]* [[T5]], i32 [[T10]] + // CHECK-NEXT: store [6 x i8]* [[T11]], [6 x i8]** [[P2]], align 4 + __typeof(p) p2 = (p + n/2) - n/4; + + // CHECK-NEXT: [[T0:%.*]] = load [6 x i8]** [[P2]], align 4 + // CHECK-NEXT: [[T1:%.*]] = load [6 x i8]** [[P]], align 4 + // CHECK-NEXT: [[T2:%.*]] = ptrtoint [6 x i8]* [[T0]] to i32 + // CHECK-NEXT: [[T3:%.*]] = ptrtoint [6 x i8]* [[T1]] to i32 + // CHECK-NEXT: [[T4:%.*]] = sub i32 [[T2]], [[T3]] + // CHECK-NEXT: [[T5:%.*]] = mul nuw i32 [[DIM0]], [[DIM1]] + // CHECK-NEXT: [[T6:%.*]] = mul nuw i32 6, [[T5]] + // CHECK-NEXT: [[T7:%.*]] = sdiv exact i32 [[T4]], [[T6]] + // CHECK-NEXT: ret i32 [[T7]] + return p2 - p; +} diff --git a/clang/test/CodeGenCXX/vla.cpp b/clang/test/CodeGenCXX/vla.cpp index cee00f27713..58cdf795ee5 100644 --- a/clang/test/CodeGenCXX/vla.cpp +++ b/clang/test/CodeGenCXX/vla.cpp @@ -24,14 +24,14 @@ void test0(void *array, int n) { array_t &ref = *(array_t*) array; // CHECK-NEXT: [[T0:%.*]] = load i16** [[REF]] - // CHECK-NEXT: [[T1:%.*]] = mul i64 1, [[DIM1]] + // CHECK-NEXT: [[T1:%.*]] = mul nsw i64 1, [[DIM1]] // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16* [[T0]], i64 [[T1]] // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16* [[T2]], i64 2 // CHECK-NEXT: store i16 3, i16* [[T3]] ref[1][2] = 3; // CHECK-NEXT: [[T0:%.*]] = load i16** [[REF]] - // CHECK-NEXT: [[T1:%.*]] = mul i64 4, [[DIM1]] + // CHECK-NEXT: [[T1:%.*]] = mul nsw i64 4, [[DIM1]] // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16* [[T0]], i64 [[T1]] // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16* [[T2]], i64 5 // CHECK-NEXT: [[T4:%.*]] = load i16* [[T3]] |

