Materialize zeros by copying from %g0, which is now marked as constant.
This makes it possible for some common operations (like integer negation) to be performed in fewer instructions.
This continues @arichardson's patch at D132561.
Paths
| Differential D138887
[SPARC] Mark the %g0 register as constant & use it to materialize zeros ClosedPublic Authored by koakuma on Nov 28 2022, 7:07 PM.
Details Summary Materialize zeros by copying from %g0, which is now marked as constant. This continues @arichardson's patch at D132561.
Diff Detail Event Timeline
Comment Actions
This revision is now accepted and ready to land.Dec 5 2022, 9:59 AM Closed by commit rG2c41310fc146: [SPARC] Mark the %g0 register as constant & use it to materialize zeros (authored by koakuma, committed by brad). · Explain WhyDec 7 2022, 10:34 AM This revision was automatically updated to reflect the committed changes. Comment Actions The tests pass fine with the clang-x86_64-debian-fast buildbot, but fail with the llvm-clang-x86_64-expensive-checks-debian buildbot.. ******************** TEST 'LLVM :: CodeGen/SPARC/bigreturn.ll' FAILED ******************** Script: -- : 'RUN: at line 2'; /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc < /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/bigreturn.ll -mtriple=sparc -disable-sparc-delay-filler -disable-sparc-leaf-proc | /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck --check-prefix=SPARC /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/bigreturn.ll : 'RUN: at line 3'; /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc < /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/bigreturn.ll -mtriple=sparc64 -disable-sparc-delay-filler -disable-sparc-leaf-proc | /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck --check-prefix=SPARC64 /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/bigreturn.ll -- Exit Code: 2 Command Output (stderr): -- + : 'RUN: at line 2' + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck --check-prefix=SPARC /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/bigreturn.ll + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -mtriple=sparc -disable-sparc-delay-filler -disable-sparc-leaf-proc # After Instruction Selection # Machine code for function ret_i64_pair: IsSSA, TracksLiveness Function Live Ins: $i2 in %2, $i3 in %3 bb.0 (%ir-block.0): liveins: $i2, $i3 %3:intregs = COPY $i3 %2:intregs = COPY $i2 %4:intpair = LDDrr %2:intregs, $g0 :: (load (s64) from %ir.p) %5:intregs = COPY %4.sub_even:intpair %6:intregs = COPY %4.sub_odd:intpair %7:intregs = ORrr $g0, $g0 %9:intpair = IMPLICIT_DEF %8:intpair = INSERT_SUBREG %9:intpair(tied-def 0), killed %7:intregs, %subreg.sub_even %10:intpair = INSERT_SUBREG %8:intpair(tied-def 0), $g0, %subreg.sub_odd STDrr %2:intregs, $g0, killed %10:intpair :: (store (s64) into %ir.p) %11:intpair = LDDrr %3:intregs, $g0 :: (load (s64) from %ir.q) %12:intregs = COPY %11.sub_even:intpair %13:intregs = COPY %11.sub_odd:intpair $i0 = COPY %5:intregs $i1 = COPY %6:intregs $i2 = COPY %12:intregs $i3 = COPY %13:intregs RETL 8, implicit $i0, implicit $i1, implicit $i2, implicit $i3 # End machine code for function ret_i64_pair. *** Bad machine code: INSERT_SUBREG expected inserted value to have equal or lesser size than the subreg it was inserted into *** - function: ret_i64_pair - basic block: %bb.0 (0x8b124a8) - instruction: %10:intpair = INSERT_SUBREG %8:intpair(tied-def 0), $g0, %subreg.sub_odd LLVM ERROR: Found 1 machine code errors. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -mtriple=sparc -disable-sparc-delay-filler -disable-sparc-leaf-proc 1. Running pass 'Function Pass Manager' on module '<stdin>'. 2. Running pass 'Verify generated machine code' on function '@ret_i64_pair' #0 0x0000000002d5f413 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2d5f413) #1 0x0000000002d5d19e llvm::sys::RunSignalHandlers() (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2d5d19e) #2 0x0000000002d5f79f SignalHandler(int) Signals.cpp:0:0 #3 0x00007f4563855140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140) #4 0x00007f4563339ce1 raise (/lib/x86_64-linux-gnu/libc.so.6+0x38ce1) #5 0x00007f4563323537 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22537) #6 0x0000000002cd2470 llvm::report_fatal_error(llvm::Twine const&, bool) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2cd2470) #7 0x00000000021a8a5f (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x21a8a5f) #8 0x00000000020e8162 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x20e8162) #9 0x000000000256da8a llvm::FPPassManager::runOnFunction(llvm::Function&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x256da8a) #10 0x00000000025742f8 llvm::FPPassManager::runOnModule(llvm::Module&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x25742f8) #11 0x000000000256e1b7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x256e1b7) #12 0x000000000075b2ec main (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x75b2ec) #13 0x00007f4563324d0a __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d0a) #14 0x000000000075894a _start (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x75894a) FileCheck error: '<stdin>' is empty. FileCheck command line: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck --check-prefix=SPARC /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/bigreturn.ll ******************** TEST 'LLVM :: CodeGen/SPARC/mult-alt-generic-sparc.ll' FAILED ******************** Script: -- : 'RUN: at line 1'; /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc < /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/mult-alt-generic-sparc.ll -march=sparc -no-integrated-as -- Exit Code: 134 Command Output (stderr): -- + : 'RUN: at line 1' + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -march=sparc -no-integrated-as # After Instruction Selection # Machine code for function single_E: IsSSA, TracksLiveness Frame Objects: fi#0: size=8, align=8, at location [SP] bb.0.entry: %0:intregs = ORrr $g0, $g0 %2:intpair = IMPLICIT_DEF %1:intpair = INSERT_SUBREG %2:intpair(tied-def 0), killed %0:intregs, %subreg.sub_even %3:intpair = INSERT_SUBREG %1:intpair(tied-def 0), $g0, %subreg.sub_odd STDri %stack.0.out0, 0, killed %3:intpair :: (store (s64) into %ir.out0) RETL 8 # End machine code for function single_E. *** Bad machine code: INSERT_SUBREG expected inserted value to have equal or lesser size than the subreg it was inserted into *** - function: single_E - basic block: %bb.0 entry (0x72aca58) - instruction: %3:intpair = INSERT_SUBREG %1:intpair(tied-def 0), $g0, %subreg.sub_odd LLVM ERROR: Found 1 machine code errors. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -march=sparc -no-integrated-as 1. Running pass 'Function Pass Manager' on module '<stdin>'. 2. Running pass 'Verify generated machine code' on function '@single_E' #0 0x0000000002d5f413 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2d5f413) #1 0x0000000002d5d19e llvm::sys::RunSignalHandlers() (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2d5d19e) #2 0x0000000002d5f79f SignalHandler(int) Signals.cpp:0:0 #3 0x00007f0e4b8c8140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140) #4 0x00007f0e4b3acce1 raise (/lib/x86_64-linux-gnu/libc.so.6+0x38ce1) #5 0x00007f0e4b396537 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22537) #6 0x0000000002cd2470 llvm::report_fatal_error(llvm::Twine const&, bool) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2cd2470) #7 0x00000000021a8a5f (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x21a8a5f) #8 0x00000000020e8162 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x20e8162) #9 0x000000000256da8a llvm::FPPassManager::runOnFunction(llvm::Function&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x256da8a) #10 0x00000000025742f8 llvm::FPPassManager::runOnModule(llvm::Module&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x25742f8) #11 0x000000000256e1b7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x256e1b7) #12 0x000000000075b2ec main (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x75b2ec) #13 0x00007f0e4b397d0a __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d0a) #14 0x000000000075894a _start (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x75894a) /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/CodeGen/SPARC/Output/mult-alt-generic-sparc.ll.script: line 1: 371281 Aborted /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -march=sparc -no-integrated-as < /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPARC/mult-alt-generic-sparc.ll This revision is now accepted and ready to land.Dec 7 2022, 4:40 PM Comment Actions
I was going to ask what the expensive checks part of the build bot name was referring to, but that is probably it. Comment Actions
This should be passed on to cmake, right? I think I haven't enabled this, let me try again with it turned on. Comment Actions
Yes. Comment Actions
You might be able to add -verify-machine-instrs to the llc command line of the failing test instead of rebuilding the compiler. Comment Actions I noticed that in the "Zero register pair" pattern, LLVM really does not like using an explicit copying from %g0 to set the lower half, even when bitcasted into i32 as in the previous version of the patch, so I generalized the pattern to match the materialization of any (0, X) register pair. This works since we really only care about preventing LLVM from selecting a register pair copy (i.e. COPY G0_G1) during the filling of the upper part. This should fix the two problematic testcases without affecting the rest. This revision was landed with ongoing or failed builds.Dec 13 2022, 2:26 PM Closed by commit rGeaade37fddec: [SPARC] Mark the %g0 register as constant & use it to materialize zeros (authored by koakuma, committed by brad). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 478543 llvm/lib/Target/Sparc/SparcInstr64Bit.td
llvm/lib/Target/Sparc/SparcInstrInfo.td
llvm/lib/Target/Sparc/SparcRegisterInfo.td
llvm/test/CodeGen/SPARC/64bit.ll
llvm/test/CodeGen/SPARC/64cond.ll
llvm/test/CodeGen/SPARC/atomics.ll
llvm/test/CodeGen/SPARC/bigreturn.ll
llvm/test/CodeGen/SPARC/cttz.ll
llvm/test/CodeGen/SPARC/float-constants.ll
llvm/test/CodeGen/SPARC/fshl.ll
llvm/test/CodeGen/SPARC/inlineasm.ll
llvm/test/CodeGen/SPARC/missinglabel.ll
llvm/test/CodeGen/SPARC/smulo-128-legalisation-lowering.ll
llvm/test/CodeGen/SPARC/tailcall.ll
llvm/test/CodeGen/SPARC/umulo-128-legalisation-lowering.ll
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/sparc_generated_funcs.ll.generated.expected
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/sparc_generated_funcs.ll.nogenerated.expected
|
This is a bit nonsense, it copies the %g0+%g1 register pair into %i4+%i5 then copies %g0 into %i5... it works but it's a regression and points at something very suspect going on