[llvm] 2a078c3 - [AttributeFuncs] Consider `align` in `typeIncompatible`

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 21:23:13 PDT 2020


Author: Johannes Doerfert
Date: 2020-10-05T23:23:05-05:00
New Revision: 2a078c3072043541ee0595aea6c8d7909f94c6f9

URL: https://github.com/llvm/llvm-project/commit/2a078c3072043541ee0595aea6c8d7909f94c6f9
DIFF: https://github.com/llvm/llvm-project/commit/2a078c3072043541ee0595aea6c8d7909f94c6f9.diff

LOG: [AttributeFuncs] Consider `align` in `typeIncompatible`

Alignment attributes need to be dropped for non-pointer values.
This also introduces a check into the verifier to ensure you don't use
`align` on anything but a pointer. Test needed to be adjusted
accordingly.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D87304

Added: 
    llvm/test/Verifier/align.ll

Modified: 
    llvm/lib/IR/Attributes.cpp
    llvm/test/Bitcode/attributes-3.3.ll
    llvm/test/Bitcode/attributes-3.3.ll.bc
    llvm/test/Bitcode/attributes.ll
    llvm/test/Transforms/DeadArgElim/returned.ll
    llvm/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
    llvm/test/Verifier/byref.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index a3940c0fa7fb..ecb0bd693edd 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1848,6 +1848,7 @@ AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) {
         .addAttribute(Attribute::NoAlias)
         .addAttribute(Attribute::NoCapture)
         .addAttribute(Attribute::NonNull)
+        .addAlignmentAttr(1)             // the int here is ignored
         .addDereferenceableAttr(1)       // the int here is ignored
         .addDereferenceableOrNullAttr(1) // the int here is ignored
         .addAttribute(Attribute::ReadNone)

diff  --git a/llvm/test/Bitcode/attributes-3.3.ll b/llvm/test/Bitcode/attributes-3.3.ll
index dc7834eaa161..2f36031f5617 100644
--- a/llvm/test/Bitcode/attributes-3.3.ll
+++ b/llvm/test/Bitcode/attributes-3.3.ll
@@ -101,8 +101,8 @@ define void @f16() sspreq
         ret void;
 }
 
-define void @f17(i8 align 4 %0)
-; CHECK: define void @f17(i8 align 4 %0)
+define void @f17(i8* align 4 %0)
+; CHECK: define void @f17(i8* align 4 %0)
 {
         ret void;
 }

diff  --git a/llvm/test/Bitcode/attributes-3.3.ll.bc b/llvm/test/Bitcode/attributes-3.3.ll.bc
index 5dd71864ea4f..f4d07b83127d 100644
Binary files a/llvm/test/Bitcode/attributes-3.3.ll.bc and b/llvm/test/Bitcode/attributes-3.3.ll.bc 
diff er

diff  --git a/llvm/test/Bitcode/attributes.ll b/llvm/test/Bitcode/attributes.ll
index 409528230a7d..d6ea794cf622 100644
--- a/llvm/test/Bitcode/attributes.ll
+++ b/llvm/test/Bitcode/attributes.ll
@@ -98,8 +98,8 @@ define void @f16() sspreq
         ret void;
 }
 
-define void @f17(i8 align 4 %0)
-; CHECK: define void @f17(i8 align 4 %0)
+define void @f17(i8* align 4 %0)
+; CHECK: define void @f17(i8* align 4 %0)
 {
         ret void;
 }

diff  --git a/llvm/test/Transforms/DeadArgElim/returned.ll b/llvm/test/Transforms/DeadArgElim/returned.ll
index f9d649498e4b..0b00a116624b 100644
--- a/llvm/test/Transforms/DeadArgElim/returned.ll
+++ b/llvm/test/Transforms/DeadArgElim/returned.ll
@@ -43,6 +43,12 @@ define internal %Ty* @test5(%Ty* %this) {
   ret %Ty* %this
 }
 
+; Drop all these attributes
+; CHECK-LABEL: define internal void @test6
+define internal align 8 dereferenceable_or_null(2) noalias i8* @test6() {
+  ret i8* null
+}
+
 define %Ty* @caller(%Ty* %this) {
   %1 = call %Ty* @test1(%Ty* %this)
   %2 = call %Ty* @test2(%Ty* %this)
@@ -51,5 +57,6 @@ define %Ty* @caller(%Ty* %this) {
 ; ...instead, drop 'returned' form the call site
 ; CHECK: call void @test5(%Ty* %this)
   %5 = call %Ty* @test5(%Ty* returned %this)
+  %6 = call i8* @test6()
   ret %Ty* %this
 }

diff  --git a/llvm/test/Transforms/LoopSimplify/unreachable-loop-pred.ll b/llvm/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
index 1e92ee4ee3bc..d116be0e4cd8 100644
--- a/llvm/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
+++ b/llvm/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
@@ -22,7 +22,7 @@ foo:
 ; When loopsimplify generates dedicated exit block for blocks that are landing
 ; pads (i.e. innerLoopExit in this test), we should not get confused with the
 ; unreachable pred (unreachableB) to innerLoopExit.
-define align 8 void @baz(i32 %trip) personality i32* ()* @wobble {
+define void @baz(i32 %trip) personality i32* ()* @wobble {
 entry:
   br label %outerHeader
 

diff  --git a/llvm/test/Verifier/align.ll b/llvm/test/Verifier/align.ll
new file mode 100644
index 000000000000..762249aa6b11
--- /dev/null
+++ b/llvm/test/Verifier/align.ll
@@ -0,0 +1,13 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: Wrong types for attribute: inalloca nest noalias nocapture nonnull readnone readonly byref(i32) byval(i32) preallocated(i32) sret(i32) align 1 dereferenceable(1) dereferenceable_or_null(1)
+; CHECK-NEXT: @align_non_pointer1
+define void @align_non_pointer1(i32 align 4 %a) {
+  ret void
+}
+
+; CHECK: Wrong types for attribute: inalloca nest noalias nocapture nonnull readnone readonly signext zeroext byref(void) byval(void) preallocated(void) sret(void) align 1 dereferenceable(1) dereferenceable_or_null(1)
+; CHECK-NEXT: @align_non_pointer2
+define align 4 void @align_non_pointer2(i32 %a) {
+  ret void
+}

diff  --git a/llvm/test/Verifier/byref.ll b/llvm/test/Verifier/byref.ll
index 5e7d5873a8db..d71fb19d7549 100644
--- a/llvm/test/Verifier/byref.ll
+++ b/llvm/test/Verifier/byref.ll
@@ -56,7 +56,7 @@ define void @byref_nest(i32* byref(i32) nest) {
   ret void
 }
 
-; CHECK: Wrong types for attribute: inalloca nest noalias nocapture nonnull readnone readonly sret byref(i32) byval(i32) preallocated(i32) dereferenceable(1) dereferenceable_or_null(1)
+; CHECK: Wrong types for attribute: inalloca nest noalias nocapture nonnull readnone readonly sret byref(i32) byval(i32) preallocated(i32) align 1 dereferenceable(1) dereferenceable_or_null(1)
 ; CHECK-NEXT: void (i32)* @byref_non_pointer
 define void @byref_non_pointer(i32 byref(i32)) {
   ret void


        


More information about the llvm-commits mailing list