[llvm] [NFC][WPD] Add constant propagation tests checking relative vtables (PR #138989)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 10:47:57 PDT 2025
================
@@ -0,0 +1,284 @@
+; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility %s | FileCheck %s
+
+;; This target uses 32-bit sized and aligned pointers.
+target datalayout = "e-p:32:32"
+
+;; Constant propagation should be agnostic towards sections.
+;; Also the new global should be in the original vtable's section.
+; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [8 x i8], [3 x ptr], [0 x i8] } { [8 x i8] c"\00\00\01\00\00\00\03\00", [3 x ptr] [ptr @vf0i1, ptr @vf1i8, ptr @vf1i32], [0 x i8] zeroinitializer }, section "vt1sec", !type [[T8:![0-9]+]]
+ at vt1 = constant [3 x ptr] [
+ptr @vf0i1,
+ptr @vf1i8,
+ptr @vf1i32
+], section "vt1sec", !type !0
+
+;; This represents a normal vtable using the default ABI alignments.
+;; For this test, the pointers are 32-bit aligned.
----------------
PiJoules wrote:
The intent of this is to show that the current WPD patches allow for this to result in unaligned loads. The things to note in this patch are
1. All the constants from the 3rd field propgating an i32 placed at an offset of `-6` from the vtable. Since this vtable is 32-bit aligned according to the datalayout, this could result in an unaligned load.
2. The call instruction in `call3` is replaced with a GEP + load.
The significant deltas in the followup patch are (1) this constant is no longer propagated since its alignment is greater than at most the alignment of any of its vtables (namely the `align 1` vtable) and (2) the GEP + load is not added and we still have a function call.
https://github.com/llvm/llvm-project/pull/138989
More information about the llvm-commits
mailing list