[all-commits] [llvm/llvm-project] 0ebb02: [RISCV] Override TargetLowering::shouldProduceAndB...
Craig Topper via All-commits
all-commits at lists.llvm.org
Wed May 11 11:13:49 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0ebb02b90a47b43e039cb7040cc9fb7dd5ec5fce
https://github.com/llvm/llvm-project/commit/0ebb02b90a47b43e039cb7040cc9fb7dd5ec5fce
Author: Craig Topper <craig.topper at sifive.com>
Date: 2022-05-11 (Wed, 11 May 2022)
Changed paths:
M llvm/lib/Target/RISCV/RISCVISelLowering.cpp
M llvm/lib/Target/RISCV/RISCVISelLowering.h
M llvm/test/CodeGen/RISCV/bittest.ll
Log Message:
-----------
[RISCV] Override TargetLowering::shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd.
This hook determines if SimplifySetcc transforms (X & (C l>>/<< Y))
==/!= 0 into ((X <</l>> Y) & C) ==/!= 0. Where C is a constant and
X might be a constant.
The default implementation favors doing the transform if X is not
a constant. Otherwise the code is left alone. There is a provision
that if the target supports a bit test instruction then the transform
will favor ((1 << Y) & X) ==/!= 0. RISCV does not say it has a variable
bit test operation.
RISCV with Zbs does have a BEXT instruction that performs (X >> Y) & 1.
Without Zbs, (X >> Y) & 1 still looks preferable to ((1 << Y) & X) since
we can fold use ANDI instead of putting a 1 in a register for SLL.
This patch overrides this hook to favor bit extract patterns and
otherwise falls back to the "do the transform if X is not a constant"
heuristic.
I've added tests where both C and X are constants with both the shl form
and lshr form. I've also added a test for a switch statement that lowers
to a bit test. That was my original motivation for looking at this.
Reviewed By: asb
Differential Revision: https://reviews.llvm.org/D124639
More information about the All-commits
mailing list