[llvm] [Analysis] Attribute Range should not prevent tail call optimization (PR #91122)

Jinsong Ji via llvm-commits llvm-commits at lists.llvm.org
Sun May 5 06:53:30 PDT 2024


https://github.com/jsji created https://github.com/llvm/llvm-project/pull/91122

- Remove Range attr when comparing for tailcall
- Add test for testcall with range


>From eead1a5d9e8686e02082e3e6c2221f88a6ce1580 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 4 May 2024 20:42:54 -0700
Subject: [PATCH 1/2] Remove Range attr when comparing for tailcall

---
 llvm/lib/CodeGen/Analysis.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index af7643d93591f7..e693cdbd0ccc1c 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -593,9 +593,10 @@ bool llvm::attributesPermitTailCall(const Function *F, const Instruction *I,
 
   // Following attributes are completely benign as far as calling convention
   // goes, they shouldn't affect whether the call is a tail call.
-  for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
-                           Attribute::DereferenceableOrNull, Attribute::NoAlias,
-                           Attribute::NonNull, Attribute::NoUndef}) {
+  for (const auto &Attr :
+       {Attribute::Alignment, Attribute::Dereferenceable,
+        Attribute::DereferenceableOrNull, Attribute::NoAlias,
+        Attribute::NonNull, Attribute::NoUndef, Attribute::Range}) {
     CallerAttrs.removeAttribute(Attr);
     CalleeAttrs.removeAttribute(Attr);
   }

>From b07946925570ba5996316f7d94d2617f2b0c89de Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sun, 5 May 2024 06:39:14 -0700
Subject: [PATCH 2/2] Add test for testcall with range

---
 llvm/test/CodeGen/X86/tailcall-range.ll | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 llvm/test/CodeGen/X86/tailcall-range.ll

diff --git a/llvm/test/CodeGen/X86/tailcall-range.ll b/llvm/test/CodeGen/X86/tailcall-range.ll
new file mode 100644
index 00000000000000..1f7712d2494326
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tailcall-range.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -passes=ipsccp -S -mtriple=x86_64-linux < %s | llc -mtriple=x86_64-linux | FileCheck %s
+
+define i32 @foo(ptr %this, ...) {
+; CHECK-LABEL: foo:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    movzbl 0, %eax
+; CHECK-NEXT:    retq
+entry:
+  %call = load volatile i1, ptr null, align 1
+  %spec.select = zext i1 %call to i32
+  ret i32 %spec.select
+}
+
+define i32 @bar(ptr %this, ...) {
+; CHECK-LABEL: bar:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    xorl %edi, %edi
+; CHECK-NEXT:    jmp foo at PLT # TAILCALL
+entry:
+  %4 = musttail call i32 (ptr, ...) @foo(ptr null, ...)
+  ret i32 %4
+}



More information about the llvm-commits mailing list