[PATCH] D94433: Do not emit non-power-of-2 alignment assume bundles (PR48713).

Ryan Mansfield via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 28 08:48:32 PDT 2021


rmansfield updated this revision to Diff 375591.
rmansfield edited the summary of this revision.
rmansfield added a comment.

Separate clang and llvm changes. I'm still looking for clarification on what clang should be emitting in the non-power of case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94433/new/

https://reviews.llvm.org/D94433

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c


Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===================================================================
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -21,7 +21,6 @@
 // CHECK-NEXT:    [[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:    store i32 [[ALIGN:%.*]], i32* [[ALIGN_ADDR]], align 4
 // CHECK-NEXT:    [[CALL:%.*]] = call i8* @alloc(i32 7)
-// CHECK-NEXT:    call void @llvm.assume(i1 true) [ "align"(i8* [[CALL]], i64 7) ]
 // CHECK-NEXT:    ret void
 //
 void t1(int align) {
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -4538,10 +4538,11 @@
     const auto *AlignmentCI = dyn_cast<llvm::ConstantInt>(Alignment);
     if (!AlignmentCI)
       return Attrs;
-    // We may legitimately have non-power-of-2 alignment here.
-    // If so, this is UB land, emit it via `@llvm.assume` instead.
-    if (!AlignmentCI->getValue().isPowerOf2())
+    // Non power-of-2 alignment is UB and rejected by the IR verifier.
+    if (!AlignmentCI->getValue().isPowerOf2()) {
+      AA = nullptr;
       return Attrs;
+    }
     llvm::AttributeList NewAttrs = maybeRaiseRetAlignmentAttribute(
         CGF.getLLVMContext(), Attrs,
         llvm::Align(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94433.375591.patch
Type: text/x-patch
Size: 1392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210928/e4d3f4eb/attachment.bin>


More information about the llvm-commits mailing list