[llvm] r345107 - ARM: handle checking aliases with out-of-bounds GEPs

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 23 17:00:52 PDT 2018


Author: compnerd
Date: Tue Oct 23 17:00:52 2018
New Revision: 345107

URL: http://llvm.org/viewvc/llvm-project?rev=345107&view=rev
Log:
ARM: handle checking aliases with out-of-bounds GEPs

A global alias may use indices which are not considered in bounds.  In
such a case, accessing the base object will fail as it only peers
through inbounds accesses.  This pattern is used by the swift compiler
to create references to preceeding members in the type metadata.  This
would cause the code generation to fail when targeting a platform that
used ELF as the object file format.  Be conservative and fail the
read-only check if we run into an alias that we cannot peer through.

Added:
    llvm/trunk/test/CodeGen/ARM/readonly-aliases.ll
Modified:
    llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp

Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=345107&r1=345106&r2=345107&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Tue Oct 23 17:00:52 2018
@@ -3171,9 +3171,11 @@ static SDValue promoteToConstantPool(con
 
 bool ARMTargetLowering::isReadOnly(const GlobalValue *GV) const {
   if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
-    GV = GA->getBaseObject();
-  return (isa<GlobalVariable>(GV) && cast<GlobalVariable>(GV)->isConstant()) ||
-         isa<Function>(GV);
+    if (!(GV = GA->getBaseObject()))
+      return false;
+  if (const auto *V = dyn_cast<GlobalVariable>(GV))
+    return V->isConstant();
+  return isa<Function>(GV);
 }
 
 SDValue ARMTargetLowering::LowerGlobalAddress(SDValue Op,

Added: llvm/trunk/test/CodeGen/ARM/readonly-aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/readonly-aliases.ll?rev=345107&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/readonly-aliases.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/readonly-aliases.ll Tue Oct 23 17:00:52 2018
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple thumbv7-unknown-linux-android -filetype asm -o - %s | FileCheck %s
+
+ at a = protected constant <{ i32, i32 }> <{ i32 0, i32 0 }>
+ at b = protected alias i32, getelementptr(i32, i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @a, i32 0, i32 1), i32 -1)
+
+declare void @f(i32*)
+
+define void @g() {
+entry:
+  call void @f(i32* @b)
+  ret void
+}
+
+; CHECK-LABEL: g:
+; CHECK: movw [[REGISTER:r[0-9]+]], :lower16:b
+; CHECK: movt [[REGISTER]], :upper16:b
+




More information about the llvm-commits mailing list