[llvm] 3d2d208 - IR: Make getRetAlign check callee function attributes

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 15:57:43 PST 2022


Author: Matt Arsenault
Date: 2022-01-12T18:21:02-05:00
New Revision: 3d2d208f6a0a421b23937c39b9d371183a5913a3

URL: https://github.com/llvm/llvm-project/commit/3d2d208f6a0a421b23937c39b9d371183a5913a3
DIFF: https://github.com/llvm/llvm-project/commit/3d2d208f6a0a421b23937c39b9d371183a5913a3.diff

LOG: IR: Make getRetAlign check callee function attributes

The attribute queries semi-consistently check the attribute set, and
then fallback to checking the callee's attributes.

Added: 
    

Modified: 
    llvm/include/llvm/IR/InstrTypes.h
    llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-assert-align.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 03839e00c7aab..fbd7e1c8a60a0 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1723,7 +1723,13 @@ class CallBase : public Instruction {
   }
 
   /// Extract the alignment of the return value.
-  MaybeAlign getRetAlign() const { return Attrs.getRetAlignment(); }
+  MaybeAlign getRetAlign() const {
+    if (auto Align = Attrs.getRetAlignment())
+      return Align;
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getRetAlignment();
+    return None;
+  }
 
   /// Extract the alignment for a call or parameter (0=unknown).
   MaybeAlign getParamAlign(unsigned ArgNo) const {

diff  --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-assert-align.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-assert-align.ll
index 35effd0e77f34..286a0a61eb0fc 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-assert-align.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-assert-align.ll
@@ -159,7 +159,8 @@ define void @declaration_result_align_8() {
   ; CHECK-NEXT:   [[COPY19:%[0-9]+]]:_(s32) = COPY $vgpr1
   ; CHECK-NEXT:   [[MV:%[0-9]+]]:_(p1) = G_MERGE_VALUES [[COPY18]](s32), [[COPY19]](s32)
   ; CHECK-NEXT:   ADJCALLSTACKDOWN 0, 0, implicit-def $scc
-  ; CHECK-NEXT:   G_STORE [[C]](s8), [[MV]](p1) :: (store (s8) into %ir.ptr, align 8, addrspace 1)
+  ; CHECK-NEXT:   [[ASSERT_ALIGN:%[0-9]+]]:_(p1) = G_ASSERT_ALIGN [[MV]], 8
+  ; CHECK-NEXT:   G_STORE [[C]](s8), [[ASSERT_ALIGN]](p1) :: (store (s8) into %ir.ptr, align 8, addrspace 1)
   ; CHECK-NEXT:   [[COPY20:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY8]]
   ; CHECK-NEXT:   S_SETPC_B64_return [[COPY20]]
   %ptr = call i8 addrspace(1)* @returns_ptr_align8()


        


More information about the llvm-commits mailing list