[PATCH] D101230: [Analysis] Attribute alignment should not prevent tail call optimization

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 24 04:58:21 PDT 2021


xbolva00 created this revision.
xbolva00 added a reviewer: dmgreen.
Herald added subscribers: pengfei, hiraditya.
xbolva00 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fixes tail folding issue mentioned in D100879 <https://reviews.llvm.org/D100879>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101230

Files:
  llvm/lib/CodeGen/Analysis.cpp
  llvm/test/CodeGen/X86/tail-calls-compatible-attrs.ll


Index: llvm/test/CodeGen/X86/tail-calls-compatible-attrs.ll
===================================================================
--- llvm/test/CodeGen/X86/tail-calls-compatible-attrs.ll
+++ llvm/test/CodeGen/X86/tail-calls-compatible-attrs.ll
@@ -34,3 +34,19 @@
   %ret = tail call dereferenceable_or_null(8) i8* @foo()
   ret i8* %ret
 }
+
+define align 8 i8* @test5() nounwind {
+; CHECK-LABEL: test5:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    jmp foo # TAILCALL
+  %ret = tail call i8* @foo()
+  ret i8* %ret
+}
+
+define i8* @test6() nounwind {
+; CHECK-LABEL: test6:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    jmp foo # TAILCALL
+  %ret = tail call align 8 i8* @foo()
+  ret i8* %ret
+}
Index: llvm/lib/CodeGen/Analysis.cpp
===================================================================
--- llvm/lib/CodeGen/Analysis.cpp
+++ llvm/lib/CodeGen/Analysis.cpp
@@ -560,14 +560,12 @@
 
   // Following attributes are completely benign as far as calling convention
   // goes, they shouldn't affect whether the call is a tail call.
-  CallerAttrs.removeAttribute(Attribute::NoAlias);
-  CalleeAttrs.removeAttribute(Attribute::NoAlias);
-  CallerAttrs.removeAttribute(Attribute::NonNull);
-  CalleeAttrs.removeAttribute(Attribute::NonNull);
-  CallerAttrs.removeAttribute(Attribute::Dereferenceable);
-  CalleeAttrs.removeAttribute(Attribute::Dereferenceable);
-  CallerAttrs.removeAttribute(Attribute::DereferenceableOrNull);
-  CalleeAttrs.removeAttribute(Attribute::DereferenceableOrNull);
+  for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
+                           Attribute::DereferenceableOrNull, Attribute::NoAlias,
+                           Attribute::NonNull}) {
+    CallerAttrs.removeAttribute(Attr);
+    CalleeAttrs.removeAttribute(Attr);
+  }
 
   if (CallerAttrs.contains(Attribute::ZExt)) {
     if (!CalleeAttrs.contains(Attribute::ZExt))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101230.340267.patch
Type: text/x-patch
Size: 1889 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210424/b958bee4/attachment.bin>


More information about the llvm-commits mailing list