[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread JF Bastien via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337041: CodeGen: specify alignment + inbounds for automatic 
variable initialization (authored by jfb, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D49209

Files:
  cfe/trunk/lib/CodeGen/CGBuilder.h
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/test/CodeGen/init.c
  cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl

Index: cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
===
--- cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
+++ cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
@@ -38,11 +38,11 @@
   // CHECK: %[[v0:.*]] = bitcast [6 x [6 x float]]* %A to i8*
   // CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %[[v0]], i8 0, i32 144, i1 false)
   // CHECK: %[[v1:.*]] = bitcast i8* %[[v0]] to [6 x [6 x float]]*
-  // CHECK: %[[v2:.*]] = getelementptr [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
-  // CHECK: %[[v3:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
-  // CHECK: store float 1.00e+00, float* %[[v3]]
-  // CHECK: %[[v4:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
-  // CHECK: store float 2.00e+00, float* %[[v4]]
+  // CHECK: %[[v2:.*]] = getelementptr inbounds [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
+  // CHECK: %[[v3:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
+  // CHECK: store float 1.00e+00, float* %[[v3]], align 4
+  // CHECK: %[[v4:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
+  // CHECK: store float 2.00e+00, float* %[[v4]], align 4
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
Index: cfe/trunk/test/CodeGen/init.c
===
--- cfe/trunk/test/CodeGen/init.c
+++ cfe/trunk/test/CodeGen/init.c
@@ -86,25 +86,25 @@
 char test8(int X) {
   char str[10] = "abc"; // tail should be memset.
   return str[X];
-// CHECK: @test8(
-// CHECK: call void @llvm.memset
-// CHECK: store i8 97
-// CHECK: store i8 98
-// CHECK: store i8 99
-// CHECK-NOT: getelementptr
-// CHECK: load
+  // CHECK-LABEL: @test8(
+  // CHECK: call void @llvm.memset
+  // CHECK: store i8 97, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 98, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 99, i8* %{{[0-9]*}}, align 1
+  // CHECK-NOT: getelementptr
+  // CHECK: load
 }
 
 void bar(void*);
 
 // PR279
-int test9(int X) {
+void test9(int X) {
   int Arr[100] = { X }; // Should use memset
   bar(Arr);
-// CHECK: @test9
-// CHECK: call void @llvm.memset
-// CHECK-NOT: store i32 0
-// CHECK: call void @bar
+  // CHECK-LABEL: @test9(
+  // CHECK: call void @llvm.memset
+  // CHECK-NOT: store i32 0
+  // CHECK: call void @bar
 }
 
 struct a {
@@ -115,11 +115,11 @@
   struct a a,b,c,d,e,f,g;
 };
 
-int test10(int X) {
+void test10(int X) {
   struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
   bar(&S);
 
-  // CHECK: @test10
+  // CHECK-LABEL: @test10(
   // CHECK: call void @llvm.memset
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
@@ -132,11 +132,11 @@
 };
 void test11(struct test11S *P) {
   *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
-  // CHECK: @test11
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
+  // CHECK-LABEL: @test11(
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
   // CHECK: ret void
 }
 
@@ -151,11 +151,11 @@
 void test13(int x) {
   struct X { int a; int b : 10; int c; };
   struct X y = {.c = x};
-  // CHECK: @test13
+  // CHECK-LABEL: @test13(
   // CHECK: and i16 {{.*}}, -1024
 }
 
-// CHECK-LABEL: @PR20473
+// CHECK-LABEL: @PR20473(
 void PR20473() {
   // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @
   bar((char[2]) {""});
@@ -168,9 +168,9 @@
 struct S14 { int a[16]; };
 
 void test14(struct S14 *s14) {
-// CHECK-LABEL: @test14
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
-// CHECK-NOT: store
-// CHECK: ret void
+  // CHECK-LABEL: @test14(
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
+  // CHECK-NOT: store
+  // CHECK: ret void
   *s14 = (struct S14) { { [5 ... 11] = 17 } };
 }
Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,17 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// st

[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lib/CodeGen/CGBuilder.h:260
+CharUnits::fromQuantity(Offset.getSExtValue(;
+  }
+

jfb wrote:
> efriedma wrote:
> > Not sure about the new helper.  We already have CreateStructGEP and 
> > CreateConstArrayGEP which do approximately what you want.
> It's close to doing what we want, but not quite? It seems like the original 
> code would have used them otherwise.
> 
> To use them we'd have to:
> 
>   - branch on struct / array
> - for struct calculate the offset there (which the new helper does)
> - for array get the element size
> 
> Seems simpler to use GEP2_32 and more fool-proof to (internal to the helper) 
> use GEP's own idea of what the offset is, no?
Okay.

(Actually, I think this ends up conservatively underestimating the alignment in 
some cases involving nested structs, but it's unlikely to matter.)


Repository:
  rC Clang

https://reviews.llvm.org/D49209



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread JF Bastien via Phabricator via cfe-commits
jfb marked an inline comment as done.
jfb added inline comments.



Comment at: lib/CodeGen/CGBuilder.h:260
+CharUnits::fromQuantity(Offset.getSExtValue(;
+  }
+

efriedma wrote:
> Not sure about the new helper.  We already have CreateStructGEP and 
> CreateConstArrayGEP which do approximately what you want.
It's close to doing what we want, but not quite? It seems like the original 
code would have used them otherwise.

To use them we'd have to:

  - branch on struct / array
- for struct calculate the offset there (which the new helper does)
- for array get the element size

Seems simpler to use GEP2_32 and more fool-proof to (internal to the helper) 
use GEP's own idea of what the offset is, no?


Repository:
  rC Clang

https://reviews.llvm.org/D49209



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 155424.
jfb added a comment.

- Simplify CreateStore.


Repository:
  rC Clang

https://reviews.llvm.org/D49209

Files:
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/init.c
  test/CodeGenOpenCL/partial_initializer.cl

Index: test/CodeGenOpenCL/partial_initializer.cl
===
--- test/CodeGenOpenCL/partial_initializer.cl
+++ test/CodeGenOpenCL/partial_initializer.cl
@@ -38,11 +38,11 @@
   // CHECK: %[[v0:.*]] = bitcast [6 x [6 x float]]* %A to i8*
   // CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %[[v0]], i8 0, i32 144, i1 false)
   // CHECK: %[[v1:.*]] = bitcast i8* %[[v0]] to [6 x [6 x float]]*
-  // CHECK: %[[v2:.*]] = getelementptr [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
-  // CHECK: %[[v3:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
-  // CHECK: store float 1.00e+00, float* %[[v3]]
-  // CHECK: %[[v4:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
-  // CHECK: store float 2.00e+00, float* %[[v4]]
+  // CHECK: %[[v2:.*]] = getelementptr inbounds [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
+  // CHECK: %[[v3:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
+  // CHECK: store float 1.00e+00, float* %[[v3]], align 4
+  // CHECK: %[[v4:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
+  // CHECK: store float 2.00e+00, float* %[[v4]], align 4
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
Index: test/CodeGen/init.c
===
--- test/CodeGen/init.c
+++ test/CodeGen/init.c
@@ -86,25 +86,25 @@
 char test8(int X) {
   char str[10] = "abc"; // tail should be memset.
   return str[X];
-// CHECK: @test8(
-// CHECK: call void @llvm.memset
-// CHECK: store i8 97
-// CHECK: store i8 98
-// CHECK: store i8 99
-// CHECK-NOT: getelementptr
-// CHECK: load
+  // CHECK-LABEL: @test8(
+  // CHECK: call void @llvm.memset
+  // CHECK: store i8 97, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 98, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 99, i8* %{{[0-9]*}}, align 1
+  // CHECK-NOT: getelementptr
+  // CHECK: load
 }
 
 void bar(void*);
 
 // PR279
-int test9(int X) {
+void test9(int X) {
   int Arr[100] = { X }; // Should use memset
   bar(Arr);
-// CHECK: @test9
-// CHECK: call void @llvm.memset
-// CHECK-NOT: store i32 0
-// CHECK: call void @bar
+  // CHECK-LABEL: @test9(
+  // CHECK: call void @llvm.memset
+  // CHECK-NOT: store i32 0
+  // CHECK: call void @bar
 }
 
 struct a {
@@ -115,11 +115,11 @@
   struct a a,b,c,d,e,f,g;
 };
 
-int test10(int X) {
+void test10(int X) {
   struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
   bar(&S);
 
-  // CHECK: @test10
+  // CHECK-LABEL: @test10(
   // CHECK: call void @llvm.memset
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
@@ -132,11 +132,11 @@
 };
 void test11(struct test11S *P) {
   *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
-  // CHECK: @test11
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
+  // CHECK-LABEL: @test11(
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
   // CHECK: ret void
 }
 
@@ -151,11 +151,11 @@
 void test13(int x) {
   struct X { int a; int b : 10; int c; };
   struct X y = {.c = x};
-  // CHECK: @test13
+  // CHECK-LABEL: @test13(
   // CHECK: and i16 {{.*}}, -1024
 }
 
-// CHECK-LABEL: @PR20473
+// CHECK-LABEL: @PR20473(
 void PR20473() {
   // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @
   bar((char[2]) {""});
@@ -168,9 +168,9 @@
 struct S14 { int a[16]; };
 
 void test14(struct S14 *s14) {
-// CHECK-LABEL: @test14
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
-// CHECK-NOT: store
-// CHECK: ret void
+  // CHECK-LABEL: @test14(
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
+  // CHECK-NOT: store
+  // CHECK: ret void
   *s14 = (struct S14) { { [5 ... 11] = 17 } };
 }
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,17 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc,
- bool isVolatile, CGBuilderTy &Builder) {
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+

[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/CGBuilder.h:260
+CharUnits::fromQuantity(Offset.getSExtValue(;
+  }
+

Not sure about the new helper.  We already have CreateStructGEP and 
CreateConstArrayGEP which do approximately what you want.



Comment at: lib/CodeGen/CGDecl.cpp:901
   isa(Init)) {
-Builder.CreateDefaultAlignedStore(Init, Loc, isVolatile);
+Builder.CreateAlignedStore(Init, Loc.getPointer(), Loc.getAlignment(),
+   isVolatile);

`Builder.CreateStore(Init, Loc, isVolatile);`


Repository:
  rC Clang

https://reviews.llvm.org/D49209



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-12 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 155287.
jfb added a comment.

- Fix silly naming and lookup.


Repository:
  rC Clang

https://reviews.llvm.org/D49209

Files:
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/init.c
  test/CodeGenOpenCL/partial_initializer.cl

Index: test/CodeGenOpenCL/partial_initializer.cl
===
--- test/CodeGenOpenCL/partial_initializer.cl
+++ test/CodeGenOpenCL/partial_initializer.cl
@@ -38,11 +38,11 @@
   // CHECK: %[[v0:.*]] = bitcast [6 x [6 x float]]* %A to i8*
   // CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %[[v0]], i8 0, i32 144, i1 false)
   // CHECK: %[[v1:.*]] = bitcast i8* %[[v0]] to [6 x [6 x float]]*
-  // CHECK: %[[v2:.*]] = getelementptr [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
-  // CHECK: %[[v3:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
-  // CHECK: store float 1.00e+00, float* %[[v3]]
-  // CHECK: %[[v4:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
-  // CHECK: store float 2.00e+00, float* %[[v4]]
+  // CHECK: %[[v2:.*]] = getelementptr inbounds [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
+  // CHECK: %[[v3:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
+  // CHECK: store float 1.00e+00, float* %[[v3]], align 4
+  // CHECK: %[[v4:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
+  // CHECK: store float 2.00e+00, float* %[[v4]], align 4
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
Index: test/CodeGen/init.c
===
--- test/CodeGen/init.c
+++ test/CodeGen/init.c
@@ -86,25 +86,25 @@
 char test8(int X) {
   char str[10] = "abc"; // tail should be memset.
   return str[X];
-// CHECK: @test8(
-// CHECK: call void @llvm.memset
-// CHECK: store i8 97
-// CHECK: store i8 98
-// CHECK: store i8 99
-// CHECK-NOT: getelementptr
-// CHECK: load
+  // CHECK-LABEL: @test8(
+  // CHECK: call void @llvm.memset
+  // CHECK: store i8 97, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 98, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 99, i8* %{{[0-9]*}}, align 1
+  // CHECK-NOT: getelementptr
+  // CHECK: load
 }
 
 void bar(void*);
 
 // PR279
-int test9(int X) {
+void test9(int X) {
   int Arr[100] = { X }; // Should use memset
   bar(Arr);
-// CHECK: @test9
-// CHECK: call void @llvm.memset
-// CHECK-NOT: store i32 0
-// CHECK: call void @bar
+  // CHECK-LABEL: @test9(
+  // CHECK: call void @llvm.memset
+  // CHECK-NOT: store i32 0
+  // CHECK: call void @bar
 }
 
 struct a {
@@ -115,11 +115,11 @@
   struct a a,b,c,d,e,f,g;
 };
 
-int test10(int X) {
+void test10(int X) {
   struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
   bar(&S);
 
-  // CHECK: @test10
+  // CHECK-LABEL: @test10(
   // CHECK: call void @llvm.memset
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
@@ -132,11 +132,11 @@
 };
 void test11(struct test11S *P) {
   *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
-  // CHECK: @test11
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
+  // CHECK-LABEL: @test11(
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
   // CHECK: ret void
 }
 
@@ -151,11 +151,11 @@
 void test13(int x) {
   struct X { int a; int b : 10; int c; };
   struct X y = {.c = x};
-  // CHECK: @test13
+  // CHECK-LABEL: @test13(
   // CHECK: and i16 {{.*}}, -1024
 }
 
-// CHECK-LABEL: @PR20473
+// CHECK-LABEL: @PR20473(
 void PR20473() {
   // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @
   bar((char[2]) {""});
@@ -168,9 +168,9 @@
 struct S14 { int a[16]; };
 
 void test14(struct S14 *s14) {
-// CHECK-LABEL: @test14
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
-// CHECK-NOT: store
-// CHECK: ret void
+  // CHECK-LABEL: @test14(
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
+  // CHECK-NOT: store
+  // CHECK: ret void
   *s14 = (struct S14) { { [5 ... 11] = 17 } };
 }
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,18 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc,
- bool isVolatile, CGBuilderTy &Builder) {
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+ 

[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-12 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

I updated the patch to use `Address`, and also use `inbounds`. This was a bit 
tricky because of the GEPs. I also updated tests which run into this codegen. 
Only the following tests actually hit this code, and not all check these stores:

  Clang :: CodeGen/2004-03-09-LargeArrayInitializers.c
  Clang :: CodeGen/indirect-goto.c
  Clang :: CodeGen/init.c
  Clang :: CodeGenCXX/float128-declarations.cpp
  Clang :: CodeGenObjC/messages-2.m
  Clang :: CodeGenObjC/messages.m
  Clang :: CodeGenOpenCL/address-space-constant-initializers.cl
  Clang :: CodeGenOpenCL/partial_initializer.cl
  Clang :: CodeGenOpenCL/private-array-initialization.cl


Repository:
  rC Clang

https://reviews.llvm.org/D49209



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-12 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 155285.
jfb marked an inline comment as done.
jfb added a comment.

- Use Address as suggested in review.


Repository:
  rC Clang

https://reviews.llvm.org/D49209

Files:
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/init.c
  test/CodeGenOpenCL/partial_initializer.cl

Index: test/CodeGenOpenCL/partial_initializer.cl
===
--- test/CodeGenOpenCL/partial_initializer.cl
+++ test/CodeGenOpenCL/partial_initializer.cl
@@ -38,11 +38,11 @@
   // CHECK: %[[v0:.*]] = bitcast [6 x [6 x float]]* %A to i8*
   // CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %[[v0]], i8 0, i32 144, i1 false)
   // CHECK: %[[v1:.*]] = bitcast i8* %[[v0]] to [6 x [6 x float]]*
-  // CHECK: %[[v2:.*]] = getelementptr [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
-  // CHECK: %[[v3:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
-  // CHECK: store float 1.00e+00, float* %[[v3]]
-  // CHECK: %[[v4:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
-  // CHECK: store float 2.00e+00, float* %[[v4]]
+  // CHECK: %[[v2:.*]] = getelementptr inbounds [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
+  // CHECK: %[[v3:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
+  // CHECK: store float 1.00e+00, float* %[[v3]], align 4
+  // CHECK: %[[v4:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
+  // CHECK: store float 2.00e+00, float* %[[v4]], align 4
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
Index: test/CodeGen/init.c
===
--- test/CodeGen/init.c
+++ test/CodeGen/init.c
@@ -86,25 +86,25 @@
 char test8(int X) {
   char str[10] = "abc"; // tail should be memset.
   return str[X];
-// CHECK: @test8(
-// CHECK: call void @llvm.memset
-// CHECK: store i8 97
-// CHECK: store i8 98
-// CHECK: store i8 99
-// CHECK-NOT: getelementptr
-// CHECK: load
+  // CHECK-LABEL: @test8(
+  // CHECK: call void @llvm.memset
+  // CHECK: store i8 97, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 98, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 99, i8* %{{[0-9]*}}, align 1
+  // CHECK-NOT: getelementptr
+  // CHECK: load
 }
 
 void bar(void*);
 
 // PR279
-int test9(int X) {
+void test9(int X) {
   int Arr[100] = { X }; // Should use memset
   bar(Arr);
-// CHECK: @test9
-// CHECK: call void @llvm.memset
-// CHECK-NOT: store i32 0
-// CHECK: call void @bar
+  // CHECK-LABEL: @test9(
+  // CHECK: call void @llvm.memset
+  // CHECK-NOT: store i32 0
+  // CHECK: call void @bar
 }
 
 struct a {
@@ -115,11 +115,11 @@
   struct a a,b,c,d,e,f,g;
 };
 
-int test10(int X) {
+void test10(int X) {
   struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
   bar(&S);
 
-  // CHECK: @test10
+  // CHECK-LABEL: @test10(
   // CHECK: call void @llvm.memset
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
@@ -132,11 +132,11 @@
 };
 void test11(struct test11S *P) {
   *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
-  // CHECK: @test11
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
+  // CHECK-LABEL: @test11(
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
   // CHECK: ret void
 }
 
@@ -151,11 +151,11 @@
 void test13(int x) {
   struct X { int a; int b : 10; int c; };
   struct X y = {.c = x};
-  // CHECK: @test13
+  // CHECK-LABEL: @test13(
   // CHECK: and i16 {{.*}}, -1024
 }
 
-// CHECK-LABEL: @PR20473
+// CHECK-LABEL: @PR20473(
 void PR20473() {
   // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @
   bar((char[2]) {""});
@@ -168,9 +168,9 @@
 struct S14 { int a[16]; };
 
 void test14(struct S14 *s14) {
-// CHECK-LABEL: @test14
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
-// CHECK-NOT: store
-// CHECK: ret void
+  // CHECK-LABEL: @test14(
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
+  // CHECK-NOT: store
+  // CHECK: ret void
   *s14 = (struct S14) { { [5 ... 11] = 17 } };
 }
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,18 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc,
- bool isVolatile, CGBuilderTy &Builder) {
+static void emitStoresForInitAfterMemset(CodeG

[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-11 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:902
+Builder.CreateAlignedStore(
+Init, Loc, Loc->getPointerAlignment(CGM.getDataLayout()), isVolatile);
 return;

llvm::Value::getPointerAlignment is not the right way to compute the alignment 
(it tries to guess the alignment based on the IR).  Please convert this to use 
a clang::CodeGen::Address instead.


Repository:
  rC Clang

https://reviews.llvm.org/D49209



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-11 Thread JF Bastien via Phabricator via cfe-commits
jfb created this revision.
Herald added subscribers: cfe-commits, dexonsmith.

Automatic variable initialization was generating default-aligned stores (which 
are deprecated) instead of using the known alignment from the alloca.


Repository:
  rC Clang

https://reviews.llvm.org/D49209

Files:
  lib/CodeGen/CGDecl.cpp


Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,18 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value 
*Loc,
- bool isVolatile, CGBuilderTy 
&Builder) {
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+ llvm::Constant *Init, llvm::Value 
*Loc,
+ bool isVolatile,
+ CGBuilderTy &Builder) {
   assert(!Init->isNullValue() && !isa(Init) &&
  "called emitStoresForInitAfterMemset for zero or undef value.");
 
   if (isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
   isa(Init)) {
-Builder.CreateDefaultAlignedStore(Init, Loc, isVolatile);
+Builder.CreateAlignedStore(
+Init, Loc, Loc->getPointerAlignment(CGM.getDataLayout()), isVolatile);
 return;
   }
 
@@ -908,7 +911,7 @@
   // If necessary, get a pointer to the element and emit it.
   if (!Elt->isNullValue() && !isa(Elt))
 emitStoresForInitAfterMemset(
-Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
 isVolatile, Builder);
 }
 return;
@@ -923,7 +926,7 @@
 // If necessary, get a pointer to the element and emit it.
 if (!Elt->isNullValue() && !isa(Elt))
   emitStoresForInitAfterMemset(
-  Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+  CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
   isVolatile, Builder);
   }
 }
@@ -1411,8 +1414,8 @@
 if (!constant->isNullValue() && !isa(constant)) {
   Loc = Builder.CreateBitCast(Loc,
 constant->getType()->getPointerTo(Loc.getAddressSpace()));
-  emitStoresForInitAfterMemset(constant, Loc.getPointer(),
-   isVolatile, Builder);
+  emitStoresForInitAfterMemset(CGM, constant, Loc.getPointer(), isVolatile,
+   Builder);
 }
   } else {
 // Otherwise, create a temporary global with the initializer then


Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,18 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc,
- bool isVolatile, CGBuilderTy &Builder) {
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+ llvm::Constant *Init, llvm::Value *Loc,
+ bool isVolatile,
+ CGBuilderTy &Builder) {
   assert(!Init->isNullValue() && !isa(Init) &&
  "called emitStoresForInitAfterMemset for zero or undef value.");
 
   if (isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
   isa(Init)) {
-Builder.CreateDefaultAlignedStore(Init, Loc, isVolatile);
+Builder.CreateAlignedStore(
+Init, Loc, Loc->getPointerAlignment(CGM.getDataLayout()), isVolatile);
 return;
   }
 
@@ -908,7 +911,7 @@
   // If necessary, get a pointer to the element and emit it.
   if (!Elt->isNullValue() && !isa(Elt))
 emitStoresForInitAfterMemset(
-Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
 isVolatile, Builder);
 }
 return;
@@ -923,7 +926,7 @@
 // If necessary, get a pointer to the element and emit it.
 if (!Elt->isNullValue() && !isa(Elt))
   emitStoresForInitAfterMemset(
-  Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+  CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
   isVolatile, Builder);
   }
 }
@@ -1411,8 +1414,8 @@
 if (!constant->isNullValue() && !isa(constant)) {
   Loc = Builder.CreateBitCast(Loc,
 constant->getType()->getPointerTo(Loc.getAddressSpace()));
-  emitStoresForInitAfterMemset(constant, Loc.getPointer(),
-   isVolatile, Builder);
+  emitStoresForI