[llvm] [DSE] Stop double-counting the dead slice offset in shortenAssignment (PR #216227)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 14 01:03:15 PDT 2026
================
@@ -0,0 +1,96 @@
+; RUN: opt %s -S -passes=dse -o - | FileCheck %s --implicit-check-not="#dbg_"
+
+;; The IR is clang's, cleaned up but not otherwise adjusted, so the variable
+;; fills its alloca and the offsets are the ones clang emitted. That gives up
+;; the coverage shorten-offset.ll buys by adjusting them, and gets a source
+;; listing whose numbers can be checked against the test.
+;;
+;; $ cat shorten.c
+;; void esc(char *);
+;; void shortenBeginPartial(void) {
+;; char local[80];
+;; __builtin_memset(local + 8, 0, 72);
+;; __builtin_memset(local + 4, 8, 64);
+;; esc(local);
+;; }
+;;
+;; $ clang -O2 -g -c -Xclang -fexperimental-assignment-tracking=forced \
+;; -mllvm -print-before=dse -mllvm -print-module-scope shorten.c \
+;; -o /dev/null
+;;
+;; and then, by hand: dropped the target triple and datalayout so this runs
+;; anywhere, dropped the tbaa metadata, llvm.ident, the producer/checksum/
+;; sysroot strings, the key-instruction atoms, the lifetime intrinsics and the
+;; function attributes, converted the debug records to intrinsics, and
+;; renumbered the metadata. The remaining non-debug instructions keep clang's
+;; order and operands, and the assignment offsets are unchanged.
+
+;; 'local' is 640 bits and starts at the alloca, so variable bit N is alloca
+;; byte N/8 throughout, which is what makes the arithmetic readable.
+;;
+;; The first memset covers bytes [8, 80) and the second covers [4, 68), so the
+;; second kills the front of the first and DSE shortens it to [68, 80). The
+;; bytes that died are [8, 68), which is variable bits [64, 544): fragment
+;; (64, 480).
+;;
+;; The dead slice stays inside the fragment, so the record keeps its size and
+;; only the offset can be wrong, and an offset that is off by the store's
+;; distance from the alloca still describes 60 plausible bytes. shorten-offset.ll
----------------
OCHyams wrote:
I'm not sure I understand what this is saying, would you be able to elaborate?
https://github.com/llvm/llvm-project/pull/216227
More information about the llvm-commits
mailing list