Page MenuHomePhabricator

[X86] Don't use sp as a loop variable in loop stack probing
DraftPublic

Authored by nagisa on Mar 19 2021, 5:59 PM.
This is a draft revision that has not yet been submitted for review.

Details

Reviewers
None
Summary

Modifying the stack pointer during such a loop will result in invalid uwtables. From experiments
done by @YangKao in D98789: [PEI] add dwarf information for stack probe it seems like modifying uwtables for this case is not feasible for
32-bit x86 targets.

This differential approaches this from the other direction – we avoid touching the sp entirely,
except once after the probing loop is over. Instead we allocate (and spill/reload, if necessary)
additional registers to hold loop variables.

This implementation should produce roughly equivalent code when register spills do not occur.

Diff Detail

Unit TestsFailed

TimeTest
50 msx64 debian > LLVM.CodeGen/X86::stack-clash-large-large-align.ll
Script: -- : 'RUN: at line 2'; /mnt/disks/ssd0/agent/llvm-project/build/bin/llc < /mnt/disks/ssd0/agent/llvm-project/llvm/test/CodeGen/X86/stack-clash-large-large-align.ll | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck /mnt/disks/ssd0/agent/llvm-project/llvm/test/CodeGen/X86/stack-clash-large-large-align.ll
50 msx64 debian > LLVM.CodeGen/X86::stack-clash-large.ll
Script: -- : 'RUN: at line 2'; /mnt/disks/ssd0/agent/llvm-project/build/bin/llc -mtriple=x86_64-linux-android < /mnt/disks/ssd0/agent/llvm-project/llvm/test/CodeGen/X86/stack-clash-large.ll | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck -check-prefix=CHECK-X86_64 /mnt/disks/ssd0/agent/llvm-project/llvm/test/CodeGen/X86/stack-clash-large.ll
30 msx64 debian > LLVM.CodeGen/X86::stack-clash-small-large-align.ll
Script: -- : 'RUN: at line 2'; /mnt/disks/ssd0/agent/llvm-project/build/bin/llc < /mnt/disks/ssd0/agent/llvm-project/llvm/test/CodeGen/X86/stack-clash-small-large-align.ll | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck /mnt/disks/ssd0/agent/llvm-project/llvm/test/CodeGen/X86/stack-clash-small-large-align.ll
2,520 msx64 debian > libarcher.races::task-two.c
Script: -- : 'RUN: at line 13'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang -fopenmp -pthread -fno-experimental-isel -g -O1 -fsanitize=thread -I /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests -I /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/runtime/src -L /mnt/disks/ssd0/agent/llvm-project/build/lib -Wl,-rpath,/mnt/disks/ssd0/agent/llvm-project/build/lib /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests/races/task-two.c -o /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/task-two.c.tmp -latomic && env TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1' /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests/deflake.bash /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/task-two.c.tmp 2>&1 | tee /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/task-two.c.tmp.log | /mnt/disks/ssd0/agent/llvm-project/build/./bin/FileCheck /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests/races/task-two.c
100 msx64 windows > LLVM.CodeGen/X86::stack-clash-large-large-align.ll
Script: -- : 'RUN: at line 2'; c:\ws\w16e2-1\llvm-project\premerge-checks\build\bin\llc.exe < C:\ws\w16e2-1\llvm-project\premerge-checks\llvm\test\CodeGen\X86\stack-clash-large-large-align.ll | c:\ws\w16e2-1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w16e2-1\llvm-project\premerge-checks\llvm\test\CodeGen\X86\stack-clash-large-large-align.ll
View Full Test Results (7 Failed)

Event Timeline

nagisa created this revision.Mar 19 2021, 5:59 PM
nagisa updated this revision to Diff 332137.Mar 20 2021, 5:08 PM

Correctly track which registers we need to clobber