[llvm] e25665f - [RISCV] Add test cases showing inefficient materialization for stores of immediates. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 12 10:14:18 PDT 2021
Author: Craig Topper
Date: 2021-08-12T10:14:07-07:00
New Revision: e25665f52eff4f99153c881df31b77824af430fe
URL: https://github.com/llvm/llvm-project/commit/e25665f52eff4f99153c881df31b77824af430fe
DIFF: https://github.com/llvm/llvm-project/commit/e25665f52eff4f99153c881df31b77824af430fe.diff
LOG: [RISCV] Add test cases showing inefficient materialization for stores of immediates. NFC
DAGCombiner::visitStore can call GetDemandedBits which will remove
upper bits from immediates. The upper bits are important for good
materialization of negative constants on RISCV. GetDemandedBits is a
different mechanism than SimplifyDemandedBits so
TargetShrinkDemandedConstant can't block it.
As far as I know this behavior is unique to stores.
I think we can fix this in isel using a concept similar to D107658.
Reviewed By: frasercrmck
Differential Revision: https://reviews.llvm.org/D107860
Added:
Modified:
llvm/test/CodeGen/RISCV/imm.ll
Removed:
################################################################################
diff --git a/llvm/test/CodeGen/RISCV/imm.ll b/llvm/test/CodeGen/RISCV/imm.ll
index ddc84775569a..4d11ca60cbe6 100644
--- a/llvm/test/CodeGen/RISCV/imm.ll
+++ b/llvm/test/CodeGen/RISCV/imm.ll
@@ -477,3 +477,40 @@ define i64 @imm_2reg_1() nounwind {
; RV64I-NEXT: ret
ret i64 -1152921504301427080 ; 0xF000_0000_1234_5678
}
+
+; FIXME: This should use a single ADDI for the immediate.
+define void @imm_store_i16_neg1(i16* %p) nounwind {
+; RV32I-LABEL: imm_store_i16_neg1:
+; RV32I: # %bb.0:
+; RV32I-NEXT: lui a1, 16
+; RV32I-NEXT: addi a1, a1, -1
+; RV32I-NEXT: sh a1, 0(a0)
+; RV32I-NEXT: ret
+;
+; RV64I-LABEL: imm_store_i16_neg1:
+; RV64I: # %bb.0:
+; RV64I-NEXT: lui a1, 16
+; RV64I-NEXT: addiw a1, a1, -1
+; RV64I-NEXT: sh a1, 0(a0)
+; RV64I-NEXT: ret
+ store i16 -1, i16* %p
+ ret void
+}
+
+; FIXME: This should use a single ADDI for the immediate.
+define void @imm_store_i32_neg1(i32* %p) nounwind {
+; RV32I-LABEL: imm_store_i32_neg1:
+; RV32I: # %bb.0:
+; RV32I-NEXT: addi a1, zero, -1
+; RV32I-NEXT: sw a1, 0(a0)
+; RV32I-NEXT: ret
+;
+; RV64I-LABEL: imm_store_i32_neg1:
+; RV64I: # %bb.0:
+; RV64I-NEXT: addi a1, zero, -1
+; RV64I-NEXT: srli a1, a1, 32
+; RV64I-NEXT: sw a1, 0(a0)
+; RV64I-NEXT: ret
+ store i32 -1, i32* %p
+ ret void
+}
More information about the llvm-commits
mailing list