This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Handle signed icmps in ARMCodeGenPrepare
ClosedPublic

Authored by samparker on Jul 31 2018, 7:36 AM.

Details

Summary

Treat signed icmps as 'sinks', allowing them to be in the use-def tree, enabling more promotions to be performed. As a sink, any promoted incoming values need to be truncated before being used by the signed icmp.

Diff Detail

Event Timeline

samparker created this revision.Jul 31 2018, 7:36 AM
SjoerdMeijer added inline comments.Aug 14 2018, 9:02 AM
test/CodeGen/ARM/arm-cgp-signed-icmps.ll
22

Perhaps better to match registers with "r[0-9]+"?

Changed test regexesess

This revision is now accepted and ready to land.Aug 15 2018, 1:13 AM
This revision was automatically updated to reflect the committed changes.

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/22348/steps/check-llvm%20asan/logs/stdio

Command Output (stderr):
--
=================================================================
==40218==ERROR: AddressSanitizer: use-after-poison on address 0x621000003dc8 at pc 0x00000168d853 bp 0x7fff0ab4e990 sp 0x7fff0ab4e988
READ of size 8 at 0x621000003dc8 thread T0
    #0 0x168d852 in getParamType /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/DerivedTypes.h:135:49
    #1 0x168d852 in Mutate /b/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp:463
    #2 0x168d852 in TryToPromote /b/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp:658
    #3 0x168d852 in (anonymous namespace)::ARMCodeGenPrepare::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp:697
    #4 0x476458d in llvm::FPPassManager::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1586:27
    #5 0x4764ba2 in llvm::FPPassManager::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1609:16
    #6 0x4765918 in runOnModule /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1669:27
    #7 0x4765918 in llvm::legacy::PassManagerImpl::run(llvm::Module&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1774
    #8 0x9f6d5f in compileModule(char**, llvm::LLVMContext&) /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llc/llc.cpp:597:8
    #9 0x9f02d0 in main /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llc/llc.cpp:351:22
    #10 0x7fdfb54d92e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #11 0x8fa609 in _start (/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/llc+0x8fa609)

0x621000003dc8 is located 200 bytes inside of 4096-byte region [0x621000003d00,0x621000004d00)
allocated by thread T0 here:
    #0 0x9b8a58 in malloc /b/sanitizer-x86_64-linux-fast/build/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:88
    #1 0xa1e27c in safe_malloc /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/MemAlloc.h:27:18
    #2 0xa1e27c in Allocate /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/Allocator.h:99
    #3 0xa1e27c in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>::StartNewSlab() /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/Allocator.h:346
    #4 0xa1df4e in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>::Allocate(unsigned long, unsigned long) /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/Allocator.h:260:5
    #5 0x482b55a in operator new<llvm::MallocAllocator, 4096, 4096> /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/Allocator.h:454:20
    #6 0x482b55a in llvm::PointerType::get(llvm::Type*, unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/Type.cpp:628
    #7 0x685b2fb in getUnqual /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/DerivedTypes.h:483:12
    #8 0x685b2fb in llvm::LLParser::ParseType(llvm::Type*&, llvm::Twine const&, bool) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/LLParser.cpp:2309
    #9 0x68605b4 in ParseType /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/LLParser.h:384:14
    #10 0x68605b4 in llvm::LLParser::ParseArgumentList(llvm::SmallVectorImpl<llvm::LLParser::ArgInfo>&, bool&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/LLParser.cpp:2475
    #11 0x682abad in llvm::LLParser::ParseFunctionHeader(llvm::Function*&, bool) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/LLParser.cpp:5147:7
    #12 0x681e75c in llvm::LLParser::ParseDefine() /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/LLParser.cpp:502:10
    #13 0x6816ac5 in llvm::LLParser::ParseTopLevelEntities() /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/LLParser.cpp:316:33
    #14 0x681682b in llvm::LLParser::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/LLParser.cpp:74:10
    #15 0x67f0ddb in llvm::parseAssemblyInto(llvm::MemoryBufferRef, llvm::Module*, llvm::ModuleSummaryIndex*, llvm::SMDiagnostic&, llvm::SlotMapping*, bool, llvm::StringRef) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/Parser.cpp:38:8
    #16 0x67f1950 in llvm::parseAssembly(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::SlotMapping*, bool, llvm::StringRef) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/AsmParser/Parser.cpp:48:7
    #17 0x48fbf3a in llvm::parseIR(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, bool, llvm::StringRef) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IRReader/IRReader.cpp:92:10
    #18 0x48fd026 in llvm::parseIRFile(llvm::StringRef, llvm::SMDiagnostic&, llvm::LLVMContext&, bool, llvm::StringRef) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IRReader/IRReader.cpp:108:10
    #19 0x9f11d5 in compileModule(char**, llvm::LLVMContext&) /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llc/llc.cpp:405:11
    #20 0x9f02d0 in main /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llc/llc.cpp:351:22
    #21 0x7fdfb54d92e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)

SUMMARY: AddressSanitizer: use-after-poison /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/DerivedTypes.h:135:49 in getParamType
Shadow bytes around the buggy address:
  0x0c427fff8760: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff8770: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff8780: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff8790: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff87a0: 00 00 00 00 f7 00 00 00 00 00 00 00 00 f7 00 00
=>0x0c427fff87b0: 00 00 f7 00 00 00 00 00 00[f7]00 00 00 00 f7 00
  0x0c427fff87c0: 00 00 00 00 00 00 00 f7 00 00 00 00 f7 f7 00 00
  0x0c427fff87d0: 00 00 f7 00 00 00 00 00 00 f7 00 00 00 00 f7 f7
  0x0c427fff87e0: 00 00 00 00 00 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c427fff87f0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c427fff8800: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
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
==40218==ABORTING
FileCheck error: '-' is empty.
FileCheck command line:  /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck /b/sanitizer-x86_64-linux-fast/build/llvm/test/CodeGen/ARM/arm-cgp-pointers.ll

--

********************
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Testing Time: 217.59s
********************
Failing Tests (1):
    LLVM :: CodeGen/ARM/arm-cgp-pointers.ll

  Expected Passes    : 26315
  Expected Failures  : 148
  Unsupported Tests  : 682
  Unexpected Failures: 1
FAILED: test/CMakeFiles/check-llvm 
cd /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/test && /usr/bin/python2.7 /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/./bin/llvm-lit -sv /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/test
ninja: build stopped: subcommand failed.
+ echo @@@STEP_FAILURE@@@
+ echo @@@BUILD_STEP check-clang asan@@@
@@@STEP_FAILURE@@@
vitalybuka reopened this revision.EditedAug 15 2018, 11:35 AM

I don't see obvious problem here.
If no one is looking into this, I am going to revert?

This revision is now accepted and ready to land.Aug 15 2018, 11:35 AM

Reverted with r339806

samparker updated this revision to Diff 160979.Aug 16 2018, 2:09 AM

Thanks for reverting. The issue was that I was assuming that the instruction operands mapped to arguments for CallInsts. Will be recommitting.

samparker closed this revision.Aug 16 2018, 5:06 AM

Fixed and recommitted in r339858.