[RISCV] Add implementation of targetShrinkDemandedConstant to optimize AND immediates.
authorCraig Topper <craig.topper@sifive.com>
Fri, 15 Jan 2021 18:54:26 +0000 (10:54 -0800)
committerCraig Topper <craig.topper@sifive.com>
Fri, 15 Jan 2021 19:14:14 +0000 (11:14 -0800)
commit86e604c4d68528478333a8901d7c79c09ca16fa8
treeb46aabb63e8f0bd2f92f14f18dee93e418cbb383
parentd0cb0d30a431578ecedb98c57780154789f3c594
[RISCV] Add implementation of targetShrinkDemandedConstant to optimize AND immediates.

SimplifyDemandedBits can remove set bits from immediates from instructions
like AND/OR/XOR. This can prevent them from being efficiently
codegened on RISCV.

This adds an initial version that tries to keep or form 12 bit
sign extended immediates for AND operations to enable use of ANDI.
If that doesn't work we'll try to create a 32 bit sign extended immediate
to use LUI+ADDIW.

More optimizations are possible for different size immediates or
different operations. But this is a good starting point that already
has test coverage.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D94628
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/test/CodeGen/RISCV/copysign-casts.ll
llvm/test/CodeGen/RISCV/frame-info.ll
llvm/test/CodeGen/RISCV/half-bitmanip-dagcombines.ll
llvm/test/CodeGen/RISCV/rv64Zbp.ll
llvm/test/CodeGen/RISCV/srem-lkk.ll
llvm/test/CodeGen/RISCV/srem-vector-lkk.ll
llvm/test/CodeGen/RISCV/stack-realignment-with-variable-sized-objects.ll
llvm/test/CodeGen/RISCV/vararg.ll