Page MenuHomePhabricator

[RISCV] Optimize (add (shl x, c0), c1)
Needs ReviewPublic

Authored by benshi001 on Mon, Oct 4, 9:59 PM.

Details

Summary
Transform (add (shl x, c0), c1) ->
          (add (shl (add x, c1>>c0), c0), c1-(c1>>c0<<c0)),
if c1>>c0 and c1-(c1>>c0<<c0) are simm12, while c1 is not.

Or transform (add (shl x, c0), c1) ->
             (shl (add x, c1>>c0), c0),
if c1-(c1>>c0<<c0) is zero, and c1>>c0 is simm12 while c1 is not.

Diff Detail

Unit TestsFailed

TimeTest
4,530 msx64 debian > libarcher.races::task-dependency.c
Script: -- : 'RUN: at line 13'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang -fopenmp -pthread -fno-experimental-isel -g -O1 -fsanitize=thread -I /var/lib/buildkite-agent/builds/llvm-project/openmp/tools/archer/tests -I /var/lib/buildkite-agent/builds/llvm-project/build/projects/openmp/runtime/src -L /var/lib/buildkite-agent/builds/llvm-project/build/lib -Wl,-rpath,/var/lib/buildkite-agent/builds/llvm-project/build/lib /var/lib/buildkite-agent/builds/llvm-project/openmp/tools/archer/tests/races/task-dependency.c -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/task-dependency.c.tmp -latomic && env TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1' /var/lib/buildkite-agent/builds/llvm-project/openmp/tools/archer/tests/deflake.bash /var/lib/buildkite-agent/builds/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/task-dependency.c.tmp 2>&1 | tee /var/lib/buildkite-agent/builds/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/task-dependency.c.tmp.log | /var/lib/buildkite-agent/builds/llvm-project/build/./bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/openmp/tools/archer/tests/races/task-dependency.c

Event Timeline

benshi001 created this revision.Mon, Oct 4, 9:59 PM
benshi001 requested review of this revision.Mon, Oct 4, 9:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMon, Oct 4, 9:59 PM
benshi001 edited the summary of this revision. (Show Details)Tue, Oct 5, 7:02 AM
benshi001 set the repository for this revision to rG LLVM Github Monorepo.
craig.topper added inline comments.Wed, Oct 13, 10:13 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6477

I think you can drop this if, getNode will see the constant is 0 and not produce an ADD node.

6483–6484

Just drop this comment. It's already above transformAddImmMulImm.

6484

This comment is already above transformAddImmShlImm, we don't need to repeat it.

benshi001 updated this revision to Diff 379574.Wed, Oct 13, 6:20 PM
benshi001 marked 3 inline comments as done.
benshi001 added inline comments.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6454

This comment also repeated before the definition of transformAddShlImm, and should also be dropped.

benshi001 updated this revision to Diff 379586.Wed, Oct 13, 7:40 PM
craig.topper added inline comments.Wed, Oct 13, 10:03 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6468

I think you need to abort if C0 is greater than VT.getSizeInBits() - 1.

benshi001 marked an inline comment as done.