From 75c64c7c4e40ec9bc16d90fee46353628d08d62d Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 5 Aug 2022 12:41:28 -0700 Subject: [RISCV] Don't use li+sh3add for constants that can use lui+add. If we're adding a constant that can't use addi we try a few tricks, one of which is using li+sh3add. We should not do this if lui+add would work. For example adding 8192. Using sh3add prevents folding a sext.w to form addw, thus increasing instruction count. --- llvm/lib/Target/RISCV/RISCVInstrInfoZb.td | 8 ++++---- llvm/test/CodeGen/RISCV/rv32zba.ll | 10 ++++++++++ llvm/test/CodeGen/RISCV/rv64zba.ll | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td index 72122d6e8830..1a7539f40d47 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td @@ -237,17 +237,17 @@ def CSImm12MulBy4 : PatLeaf<(imm), [{ if (!N->hasOneUse()) return false; int64_t C = N->getSExtValue(); - // Skip if C is simm12 or can be optimized by the PatLeaf AddiPair. - return !isInt<13>(C) && isShiftedInt<12, 2>(C); + // Skip if C is simm12, an lui, or can be optimized by the PatLeaf AddiPair. + return !isInt<13>(C) && !isShiftedInt<20, 12>(C) && isShiftedInt<12, 2>(C); }]>; def CSImm12MulBy8 : PatLeaf<(imm), [{ if (!N->hasOneUse()) return false; int64_t C = N->getSExtValue(); - // Skip if C is simm12 or can be optimized by the PatLeaf AddiPair or + // Skip if C is simm12, an lui or can be optimized by the PatLeaf AddiPair or // CSImm12MulBy4. - return !isInt<14>(C) && isShiftedInt<12, 3>(C); + return !isInt<14>(C) && !isShiftedInt<20, 12>(C) && isShiftedInt<12, 3>(C); }]>; def SimmShiftRightBy2XForm : SDNodeXForm