This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] SIFoldOperands: eagerly erase dead REG_SEQUENCEs
ClosedPublic

Authored by foad on Apr 9 2021, 6:11 AM.

Details

Summary

This is fairly cheap to implement and means less work for future
passes like MachineDCE.

Diff Detail

Event Timeline

foad created this revision.Apr 9 2021, 6:11 AM
foad requested review of this revision.Apr 9 2021, 6:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2021, 6:11 AM
foad added inline comments.Apr 9 2021, 6:13 AM
llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
1547

Do we actually need to follow copies here? I don't see any lit tests regressions if I remove this loop.

rampitec accepted this revision.Apr 9 2021, 10:44 AM
rampitec added inline comments.
llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
1547

The relevant test was in the acc-ldst.ll at least initially, all the subtests with loops. It was written to fold a store from LCSSA PHI. We had too many changes since then though so the test probably lost some of its value, but the code is still relevant.

This revision is now accepted and ready to land.Apr 9 2021, 10:44 AM
This revision was automatically updated to reflect the committed changes.
hctim added a subscriber: hctim.Apr 9 2021, 3:04 PM

Looks like this patch might have broken the ASan buildbots (https://lab.llvm.org/buildbot/#/builders/99/builds/2766):

Waiting on that build to finish and bisecting locally, but here's the ASan report from one of the relevant test failures. Full repro instructions at
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild, but I believe this should be reproducible using check-llvm with cmake -DLLVM_USE_SANITIZER=Address.

FAIL: LLVM :: CodeGen/AMDGPU/wwm-reserved.ll (35874 of 75435)
******************** TEST 'LLVM :: CodeGen/AMDGPU/wwm-reserved.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/llc -O0 -march=amdgcn -mcpu=gfx900 -amdgpu-dpp-combine=false -verify-machineinstrs < /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/test/CodeGen/AMDGPU/wwm-reserved.ll | /b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/FileCheck -check-prefixes=GFX9,GFX9-O0 /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/test/CodeGen/AMDGPU/wwm-reserved.ll
: 'RUN: at line 2';   /b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/llc -march=amdgcn -mcpu=gfx900 -amdgpu-dpp-combine=false -verify-machineinstrs < /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/test/CodeGen/AMDGPU/wwm-reserved.ll | /b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/FileCheck -check-prefixes=GFX9,GFX9-O3 /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/test/CodeGen/AMDGPU/wwm-reserved.ll
--
Exit Code: 2
Command Output (stderr):
--
=================================================================
==28739==ERROR: AddressSanitizer: use-after-poison on address 0x621000278298 at pc 0x000005ad3340 bp 0x7fff5c6564f0 sp 0x7fff5c6564e8
READ of size 8 at 0x621000278298 thread T0
    #0 0x5ad333f in getOpcode /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/CodeGen/MachineInstr.h:478:39
    #1 0x5ad333f in isRegSequence /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/CodeGen/MachineInstr.h:1272:12
    #2 0x5ad333f in (anonymous namespace)::SIFoldOperands::runOnMachineFunction(llvm::MachineFunction&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp:1807:39
    #3 0x91e1d53 in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:72:13
    #4 0x9fbe63c in llvm::FPPassManager::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1439:27
    #5 0x847fa3b in RunPassOnSCC /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:178:25
    #6 0x847fa3b in RunAllPassesOnSCC /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:476:9
    #7 0x847fa3b in (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:541:18
    #8 0x9fc08b8 in runOnModule /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1554:27
    #9 0x9fc08b8 in llvm::legacy::PassManagerImpl::run(llvm::Module&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:542:44
    #10 0x4b13085 in compileModule /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/tools/llc/llc.cpp:687:8
    #11 0x4b13085 in main /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/tools/llc/llc.cpp:388:22
    #12 0x7f164c90a09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
    #13 0x4a336e9 in _start (/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/llc+0x4a336e9)
0x621000278298 is located 3480 bytes inside of 4096-byte region [0x621000277500,0x621000278500)
allocated by thread T0 here:
    #0 0x4b09ee8 in operator new(unsigned long) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:99:3
    #1 0x4f7d4b6 in Allocate /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/Support/AllocatorBase.h:85:12
    #2 0x4f7d4b6 in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>::StartNewSlab() /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/Support/Allocator.h:335:21
    #3 0x4f7d1d2 in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>::Allocate(unsigned long, llvm::Align) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/Support/Allocator.h:190:5
    #4 0x91baad7 in Allocate /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/Support/Allocator.h:204:12
    #5 0x91baad7 in operator new<llvm::MallocAllocator, 4096, 4096, 128> /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/Support/Allocator.h:437:20
    #6 0x91baad7 in llvm::MachineFunction::init() /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/CodeGen/MachineFunction.cpp:160:15
    #7 0x9279d61 in llvm::MachineModuleInfo::getOrCreateMachineFunction(llvm::Function&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/CodeGen/MachineModuleInfo.cpp:296:14
    #8 0x91e1b8b in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:44:29
    #9 0x9fbe63c in llvm::FPPassManager::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1439:27
    #10 0x847fa3b in RunPassOnSCC /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:178:25
    #11 0x847fa3b in RunAllPassesOnSCC /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:476:9
    #12 0x847fa3b in (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:541:18
    #13 0x9fc08b8 in runOnModule /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1554:27
    #14 0x9fc08b8 in llvm::legacy::PassManagerImpl::run(llvm::Module&) /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:542:44
    #15 0x4b13085 in compileModule /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/tools/llc/llc.cpp:687:8
    #16 0x4b13085 in main /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/tools/llc/llc.cpp:388:22
    #17 0x7f164c90a09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
SUMMARY: AddressSanitizer: use-after-poison /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/llvm/include/llvm/CodeGen/MachineInstr.h:478:39 in getOpcode
Shadow bytes around the buggy address:
  0x0c4280047000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f7
  0x0c4280047010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4280047020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4280047030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4280047040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c4280047050: f7 f7 f7[f7]f7 f7 f7 f7 f7 f7 f7 00 00 00 00 00
  0x0c4280047060: 00 00 00 00 f7 00 00 00 00 00 00 00 00 00 f7 00
  0x0c4280047070: 00 00 00 00 00 00 00 f7 00 00 00 00 00 00 00 00
  0x0c4280047080: 00 f7 00 00 00 00 00 00 00 00 f7 00 00 00 00 00
  0x0c4280047090: 00 00 00 00 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c42800470a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==28739==ABORTING