[all-commits] [llvm/llvm-project] 2661e9: [llvm] Ensure propagated constants in the vtable a...

PiJoules via All-commits all-commits at lists.llvm.org
Thu May 15 11:52:48 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2661e995ceebd6fd083e5b62aeff21e67b28e9a4
      https://github.com/llvm/llvm-project/commit/2661e995ceebd6fd083e5b62aeff21e67b28e9a4
  Author: PiJoules <6019989+PiJoules at users.noreply.github.com>
  Date:   2025-05-15 (Thu, 15 May 2025)

  Changed paths:
    M llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
    M llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
    M llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
    M llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
    M llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-small-alignment-32.ll
    M llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-small-alignment-64.ll
    M llvm/unittests/Transforms/IPO/WholeProgramDevirt.cpp

  Log Message:
  -----------
  [llvm] Ensure propagated constants in the vtable are aligned (#136630)

It's possible for virtual constant propagation in whole program
devirtualization to create unaligned loads. We originally saw this with
4-byte aligned relative vtables where we could store 8-byte values
before/after the vtable. But since the vtable is 4-byte aligned and we
unconditionally do an 8-byte load, we can't guarantee that the stored
constant will always be aligned to 8 bytes. We can also see this with
normal vtables whenever a 1-byte char is stored in the vtable because
the offset calculation for the GEP doesn't take into account the
original vtable alignment.

This patch introduces two changes to virtual constant propagation:
1. Do not propagate constants whose preferred alignment is larger than
the vtable alignment. This is required because if the constants are
stored in the vtable, we can only guarantee the constant will be stored
at an address at most aligned to the vtable's alignment.
2. Round up the offset used in the GEP before the load to ensure it's at
an address suitably aligned such that we can load from it.

This patch updates tests to reflect this alignment change and adds some
cases for relative vtables.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list