Page MenuHomePhabricator

[LoongArch] Add support for selecting constant materializations.
ClosedPublic

Authored by wangleiat on Apr 7 2022, 1:43 AM.

Details

Summary

Integer materializing can generate LU12I_W, ORI, LU32I_D, LU52I_D and
ADDI_W instructions.

According to the sign-extended behavior of these instructions
(except ORI), the generated instruction sequence can be improved.

For example, load -1 into general register:
The ADDI_W instruction performs the operation that the [31:0] bit data
in the general register rj plus the 12-bit immediate simm12 sign
extension 32-bit data; the resultant [31:0] bit is sign extension, then
written into the general register rd.

Normal sequence:

lu12i.w $a0, -1
ori $a0, $a0, 2048

Improved with sign-extended instruction:

addi.w $a0, $zero,  -1

Change-Id: Ifd72aa1cc21f4032243d7c2ba0171767b58910eb

Diff Detail

Unit TestsFailed

TimeTest
60,130 msx64 debian > AddressSanitizer-x86_64-linux-dynamic.TestCases::scariness_score_test.cpp
Script: -- : 'RUN: at line 4'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -m64 -shared-libasan -O0 /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/asan/TestCases/scariness_score_test.cpp -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/asan/X86_64LinuxDynamicConfig/TestCases/Output/scariness_score_test.cpp.tmp
60,130 msx64 debian > AddressSanitizer-x86_64-linux.TestCases::scariness_score_test.cpp
Script: -- : 'RUN: at line 4'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -m64 -O0 /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/asan/TestCases/scariness_score_test.cpp -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/asan/X86_64LinuxConfig/TestCases/Output/scariness_score_test.cpp.tmp

Event Timeline

wangleiat created this revision.Apr 7 2022, 1:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2022, 1:43 AM
wangleiat requested review of this revision.Apr 7 2022, 1:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2022, 1:43 AM
MaskRay added inline comments.Apr 7 2022, 5:46 PM
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp
24

Add const if applicable

45

The logic looks weird. What does it do?

wangleiat added inline comments.Apr 7 2022, 7:06 PM
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.cpp
24

Thanks, I will add it.

45

It is to check whether Higher20 is equal to the repetition of the 31st bit.
This judgment is made because these LU12I_W ADDI_W instructions will writes imm into the general register after sign extension.

wangleiat updated this revision to Diff 421386.Apr 7 2022, 7:12 PM

Add const modifiers.

SixWeining accepted this revision.Apr 10 2022, 9:15 PM

LGTM

llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
15

abc

foreach ($list as $item) {
  work_miracles($item);
}
This revision is now accepted and ready to land.Apr 10 2022, 9:15 PM
SixWeining added inline comments.Apr 10 2022, 10:26 PM
llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
15

Sorry for the mess which is not my intention.

wangleiat requested review of this revision.Apr 14 2022, 4:36 AM

Is it necessary to have the 4483 line test? To cover all the code paths in the function, it is possible to use significantly fewer tests.

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.h
29

Add one blank line before the header guard #endif

wangleiat updated this revision to Diff 423006.Apr 14 2022, 8:03 PM

Reduce the test cases and simply cover all the code paths in generateInstSeq

wangleiat added inline comments.Apr 14 2022, 8:04 PM
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMatInt.h
29

Ok, thanks.

MaskRay accepted this revision.Apr 14 2022, 8:31 PM

Thanks!

This revision is now accepted and ready to land.Apr 14 2022, 8:31 PM
SixWeining accepted this revision.Apr 14 2022, 8:45 PM
This revision was landed with ongoing or failed builds.Apr 14 2022, 9:09 PM
This revision was automatically updated to reflect the committed changes.