[PATCH] D77248: [IR] Strip constant inbound GEPs when checking Constant::needsRelocation()

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 15:45:48 PDT 2020


leonardchan created this revision.
leonardchan added reviewers: rnk, pcc, eugenis.
leonardchan added a project: LLVM.
Herald added a subscriber: hiraditya.
leonardchan added a child revision: D72959: Relative VTables ABI on Fuchsia.
leonardchan removed a child revision: D72959: Relative VTables ABI on Fuchsia.
leonardchan added a parent revision: D72959: Relative VTables ABI on Fuchsia.

This allows constant indexed GEPs of relative pointers to also not need a dynamic reloc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77248

Files:
  llvm/lib/IR/Constants.cpp
  llvm/test/CodeGen/X86/relptr-rodata.ll


Index: llvm/test/CodeGen/X86/relptr-rodata.ll
===================================================================
--- llvm/test/CodeGen/X86/relptr-rodata.ll
+++ llvm/test/CodeGen/X86/relptr-rodata.ll
@@ -19,3 +19,27 @@
 ; CHECK: relro2:
 ; CHECK: .long hidden-relro2
 @relro2 = constant i32 trunc (i64 sub (i64 ptrtoint (i8* @hidden to i64), i64 ptrtoint (i32* @relro2 to i64)) to i32)
+
+; CHECK:      .section .rodata.cst16
+; CHECK-NEXT: .globl _ZTV4Test
+; CHECK:      _ZTV4Test
+; CHECK:      .quad 0
+; CHECK:      .long (_ZTI4Test.rtti_proxy-_ZTV4Test)-12
+; CHECK:      .long (_ZN4TestD1Ev.stub at PLT-_ZTV4Test)-12
+
+ at _ZTI4Test = external global i8
+ at _ZTI4Test.rtti_proxy = hidden unnamed_addr constant i8* @_ZTI4Test
+
+declare void @_ZN4TestD2Ev()
+define hidden void @_ZN4TestD1Ev.stub() unnamed_addr {
+entry:
+  tail call void @_ZN4TestD2Ev()
+  ret void
+}
+
+ at _ZTV4Test = dso_local unnamed_addr constant { { i8*, i32, i32 } } {
+  { i8*, i32, i32 } {
+    i8* null,
+    i32 trunc (i64 sub (i64 ptrtoint (i8** @_ZTI4Test.rtti_proxy to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @_ZTV4Test, i32 0, i32 0, i32 2) to i64)) to i32),
+    i32 trunc (i64 sub (i64 ptrtoint (void ()* @_ZN4TestD1Ev.stub to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @_ZTV4Test, i32 0, i32 0, i32 2) to i64)) to i32)
+  } }, align 8
Index: llvm/lib/IR/Constants.cpp
===================================================================
--- llvm/lib/IR/Constants.cpp
+++ llvm/lib/IR/Constants.cpp
@@ -571,8 +571,8 @@
           return false;
 
         // Relative pointers do not need to be dynamically relocated.
-        if (auto *LHSGV = dyn_cast<GlobalValue>(LHSOp0->stripPointerCasts()))
-          if (auto *RHSGV = dyn_cast<GlobalValue>(RHSOp0->stripPointerCasts()))
+        if (auto *LHSGV = dyn_cast<GlobalValue>(LHSOp0->stripInBoundsConstantOffsets()))
+          if (auto *RHSGV = dyn_cast<GlobalValue>(RHSOp0->stripInBoundsConstantOffsets()))
             if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
               return false;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77248.254324.patch
Type: text/x-patch
Size: 2146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200401/6fc7b1af/attachment.bin>


More information about the llvm-commits mailing list