335 Commits

Author SHA1 Message Date
Shaoce SUN
7e8ff2afa9
[RISCV][GISel] Optimize +0.0 to use fcvt.d.w for s64 on rv32 (#153978)
Resolve the TODO: on RV32, when constructing the double-precision
constant `+0.0` for `s64`, `BuildPairF64Pseudo` can be optimized to use
the `fcvt.d.w` instruction to generate the result directly.
2025-08-18 17:52:24 +00:00
Nikita Popov
406d9b1dd6
[CodeGen] Move IsFixed into ArgFlags (NFCI) (#152319)
The information whether a specific argument is vararg or fixed is
currently stored separately from all the other argument information in
ArgFlags. This means that it is not accessible from CCAssign, and
backends have developed all kinds of workarounds for how they can access
it after all.

Move this information to ArgFlags to make it directly available in all
relevant places.

I've opted to invert this and store it as IsVarArg, as I think that both
makes the meaning more obvious and provides for a better default (which
is IsVarArg=false).
2025-08-07 09:12:40 +02:00
Kazu Hirata
7114cfbd57 [RISCV] Fix a warning
This patch fixes:

  llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp:590:19: error:
  unused variable 'F' [-Werror,-Wunused-variable]
2025-05-30 10:27:57 -07:00
Dudeldu
ed71a4ff64
[RISCV][GISel] Use the correct calling convention during call lowering (#142148) 2025-05-30 18:55:32 +02:00
Rahul Joshi
52c2e45c11
[NFC][CodeGen] Adopt MachineFunctionProperties convenience accessors (#141101) 2025-05-23 08:30:29 -07:00
David Green
ec406e8674
[GlobalISel] Add a GISelValueTracker printing pass (#139687)
This adds a GISelValueTrackingPrinterPass that can print the known bits
and sign bit of each def in a function. It is built on the new pass
manager and so adds a NPM GISelValueTrackingAnalysis, renaming the older
class to GISelValueTrackingAnalysisLegacy.

The first 2 functions from the AArch64GISelMITest are ported over to an
mir test to show it working. It also runs successfully on all files in
llvm/test/CodeGen/AArch64/GlobalISel/*.mir that are not invalid. It can
hopefully be used to test GlobalISel known bits analysis more directly
in common cases, without jumping through the hoops that the C++ tests
requires.
2025-05-14 11:05:04 +01:00
Kazu Hirata
d144c13ae5
[Target] Remove unused local variables (NFC) (#138443) 2025-05-04 07:56:38 -07:00
Jim Lin
0439a4eca7
[RISCV] Add new CondCode COND_CV_BEQIMM/COND_CV_BNEIMM for CV immediate branch (#135771)
If there is another branch instruction also with immediate operand, but
it is used to specify which bit to be tested is set or clear. We only
check whether operand2 is immediate or not here. There are no way to
distinguish between them.

So add new CondCode COND_CV_BEQIMM/COND_CV_BNEIMM that we can know what
kinds of immediate branch instruction are matched in Select_* Pseudo.
2025-04-16 10:16:31 +08:00
Rahul Joshi
b393ca6026
[NFC][LLVM][RISCV] Cleanup pass initialization for RISCV (#134279)
- Move calls to pass initialization functions to RISCV target
initialization and remove them from pass constructors.
2025-04-03 11:28:45 -07:00
Ningning Shi(史宁宁)
6b647de031
[NFC] Remove the unused hasMinSize() (#133838)
The 'hasOptSize()' is 'hasFnAttribute(Attribute::OptimizeForSize) ||
hasMinSize()', so we don't need another 'hasMinSize()'.
2025-04-01 15:23:34 +08:00
Tim Gymnich
1d0005a69a
[GlobalISel][NFC] Rename GISelKnownBits to GISelValueTracking (#133466)
- rename `GISelKnownBits` to `GISelValueTracking` to analyze more than
just `KnownBits` in the future
2025-03-29 11:51:29 +01:00
Sudharsan Veeravalli
6262d67446
[RISCV] Check subtarget feature in getBrCond (#129859)
The function currently only checks to see if we compare against an
immediate before selecting the two branch immediate instructions that
are a part of the XCVbi vendor extension. This works at the moment since
there are no other extensions that have a branch immediate instruction.
It would be better if we explicitly check if the XCVbi extension is enabled
before returning the appropriate instruction.

This is also done in preparation for the branch immediate instructions
that are a part of the Xqcibi vendor extension from Qualcomm.
2025-03-05 19:38:40 +05:30
Craig Topper
0cc532b79e
[RISCV] Move the RISCVII namespaced enums into RISCVVType namespace in RISCVTargetParser.h. NFC (#127585)
The VLMUL and policy enums originally lived in RISCVBaseInfo.h in the
backend which is where everything else in the RISCVII namespace is
defined.

RISCVTargetParser.h is used by much more of the compiler and it
doesn't really make sense to have 2 different namespaces exposed.
These enums are both associated with VTYPE so using the RISCVVType
namespace seems like a good home for them.
2025-02-18 08:27:25 -08:00
Sudharsan Veeravalli
83783e8bec
[RISCV] Fix typos discovered by codespell (NFC) (#126191)
Found using https://github.com/codespell-project/codespell

```
codespell RISCV --write-changes \
       --ignore-words-list=FPR,fpr,VAs,ORE,WorstCase,hart,sie,MIs,FLE,fle,CarryIn,vor,OLT,VILL,vill,bu,pass-thru 
```
2025-02-07 13:35:30 +05:30
Luke Quinn
d5666294e9
[RISCV] Porting hasAllNBitUsers to RISCV GISel for instruction select (#125795)
Ported hasAllNBitUsers to RISCV GISel side. Add GISelPredicate code to
each of the 16,32, and 64 bit words. It allows for generation of
optimized packw sequences along with other transparent narrowing
operations. Included a few new .ll files to expand testing and limited
the OptW pass Optimization to fewer options until GISel is ready for
more code generation paths

---------

Signed-off-by: Luke Quinn <quic_lquinn@quicinc.com>
2025-02-06 11:57:52 -05:00
Craig Topper
fc3ec135d3 [RISCV][GISel] Remove unused function leftover from a removed SDNodeXForm. NFC
Fixes #125551
2025-02-03 11:01:57 -08:00
Luke Quinn
dde5546b79
[RISCV] GISel custom lowering for G_ADD/G_SUB (#121587)
Custom lowering for s32 G_ADD/SUB to help match selection dag better.
Specifically for RV64 a s32 is produced as a add+sext the output this
allows for fewer instructions to sign extend a couple patterns. Allows
for the generation of addiw,subw,negw to reduce required instructions to
load values quicker

Log2_ceil_i32 in rvzbb.ll shows a more obvious improvement case.
2025-01-07 18:53:10 -08:00
Craig Topper
785b16ad04
[RISCV][GISel] Support G_MERGE_VALUES/G_UNMERGE_VALUES with Zfa. (#120379)
Without Zfa we use pseudos that are lowered to a stack load/store. With
Zfa we have instructions that can move a pair of registers to an FPR. Or
move the high or low half of an FPR to a GPR.

I've used a GINodeEquiv to make use of 3 of the 4 tablegen patterns. The
split case with Zfa requires 2 instructions which I'm doing through
custom isel like we do in SelectionDAG.
2025-01-07 07:50:50 -08:00
Sergei Barannikov
ce393beddf
[RISCV] Pattern-match frameindex (#120917) 2024-12-23 13:19:00 +03:00
Luke Quinn
6ab8401f53
[RISCV][GISel] Port AddiPair optimization (#120463)
Check if (add r, imm) can be optimized to (ADDI (ADDI r, imm0), imm1),
in which imm = imm0 + imml and both imm0 and imm1 are simm12. We make
imm0 as large as possible and imm1 as small as possible so that we might
be able to use c.addi for the small immediate.
2024-12-20 11:32:27 -08:00
Paul Bowen-Huggett
ee7ca0ddda
Make CombinerHelper methods const (#119529)
There are a number of backends (specifically AArch64, AMDGPU, Mips, and
RISCV) which contain a “TODO: make CombinerHelper methods const”
comment. This PR does just that and makes all of the CombinerHelper
methods const, removes the TODO comments and makes the associated
instances const. This change makes some sense because the CombinerHelper
class simply modifies the state of _other_ objects to which it holds
pointers or references.

Note that AMDGPU contains an identical comment for an instance of
AMDGPUCombinerHelper (a subclass of CombinerHelper). I deliberately
haven’t modified the methods of that class in order to limit the scope
of the change. I’m happy to do so either now or as a follow-up.
2024-12-20 08:29:18 +07:00
Craig Topper
43ede46898 [RISCV][GISel] Add legalization for more fp128 libcalls. 2024-12-16 23:39:09 -08:00
Craig Topper
d78fe84d49
[RISCV][GISel] Port TrailingOnesMask PatLeaf. (#119427) 2024-12-10 22:17:52 -08:00
Craig Topper
82f4ebf1ba
[RISCV][GISel] Fallback in LowerCall for byval arguments. (#119251)
Our byval call lowering isn't copying the argument. Looks like our
SelectionDAG code for byval is different than AArch64 so this may be
non-trivial to fix. Reject for now.
2024-12-09 14:22:05 -08:00
Craig Topper
e0ea9fd6dc
[RISCV][GISel] Lower G_SCMP and G_UCMP. (#119112)
Codegen is not optimal for RISC-V yet. We should port the (sub (setgt X,
Y), (setlt X, Y)) lowering from SelectionDAG.
2024-12-08 23:32:22 -08:00
Craig Topper
ab0dc290bc [RISCV][GISel] Allow s32 G_PHI for RV64 to support f32 phis. 2024-12-06 11:53:57 -08:00
Craig Topper
37b10af6a0 [RISCV][GISel] Use correct shift width for GIShiftMask32 ComplexOperandMatcher.
We should use 32 instead of XLen. This allows us to remove
'and X, 31' from the shift amount.
2024-12-05 15:52:41 -08:00
Luke Quinn
22774bbea1
[RISCV][GISel] Add Zfa FP legalization and full tests for 9 insn (#118723)
ceil, floor, round, roundeven, trunc, rint, nearbyint, maximum, minimum.
2024-12-05 12:49:07 -08:00
Craig Topper
41c33cbf36 [RISCV][GISel] Enable support for ArrayType arguments if the element type is also supported.
This allows us to handle small coerced structs that are passed as
[2 x i64]. This is one of the last big reasons for -O0 fallbacks
in some of my testing.
2024-12-05 09:42:05 -08:00
Craig Topper
3e0e1c13ce
[RISCV][GISel] Support fp128 arithmetic and conversion for RV64. (#118707)
We can support these via libcalls in libgcc/compiler-rt or integer
operations for fneg/fabs/fcopysign. fp128 values will be passed in two
64-bit GPRs according to the psABI.

Supporting RV32 requires sret which is not supported by libcall handling
in LegalizerHelper.cpp yet. It doesn't call canLowerReturn.
2024-12-04 21:43:29 -08:00
Craig Topper
2fea1ccb62 [RISCV][GISel] Correct the widening predicate for G_SITOFP/G_UITOFP.
This happened to coincidentally work due to D and Zfh both depending
on the F extension.

It breaks when I tried to add fp128 libcall support.
2024-12-04 14:35:44 -08:00
Craig Topper
4cf2cf18c9
[RISCV][GISel] Stop over promoting G_SITOFP/UITOFP libcalls on RV64. (#118597)
When we have legal instructions we want to promote to sXLen and let isel
pattern matching removing the and/sext_inreg.

When using a libcall we want to use a 'si' libcall for small types
instead of 'di'. To match the RV64 ABI, we need to sign extend `unsigned
int` arguments. We reuse the shouldSignExtendTypeInLibCall hook from
SelectionDAG.
2024-12-04 10:42:49 -08:00
Craig Topper
9692242f51 [RISCV][GISel] Support f64->f32 fptrunc and f32->f64 fpext without D extension.
Add RUN lines to float-convert.ll and double-convert.ll without F
extension.
2024-12-02 23:50:32 -08:00
Craig Topper
fdc7ccf543 [RISCV][GISel] Allow fp128 function arguments.
Add more testing for large arguments.
2024-12-02 15:38:46 -08:00
Craig Topper
a15400d05d
[RISCV][GISel] Support f32/f64 ldexp. (#117941)
The existing libcall lowering in LegalizerHelper.cpp did not account
for one operand being integer. Reuse the G_FPOWI code to fix this.
2024-12-02 13:30:46 -08:00
Luke Quinn
de6d0d2de0
[RISCV][GISel] Add FCLASS to onlyUsesFP for register bank selection (#118021)
Bug fix FCLASS instruction in RISCV. The bug is due the fact that FCLASS
has an input float register and output GPR this caused reg bank select
regression.
2024-12-02 11:19:08 -08:00
Craig Topper
bee33b5291
[RISCV][GISel] Support f32/f64 powi. (#117937)
Need to force libcall legalization to treat the integer argument as
signed so that it can be promoted to XLen in call lowering for RV64.
Alternatively we could promote the operand before converting to libcall,
but going through call lowering is closer to what SelectionDAG does.
2024-12-02 09:06:38 -08:00
Craig Topper
175051b05e [RISCV][GISel] Support libcalls for f32/f64 acos/asin/atan/atan2/cosh/sinh/tanh. 2024-11-27 12:23:12 -08:00
Craig Topper
d7643e8610 [RISCV][GISel] Support f32/f64 llvm.exp10 intrinsics. 2024-11-27 10:24:33 -08:00
Craig Topper
50dfb0772b [RISCV] Support f32/f64 libcalls for sin/cos/pow/log/log2/log10/exp/exp2
Test cases copied from SelectionDAG.
2024-11-26 23:35:52 -08:00
Craig Topper
43b6b78771
[RISCV][GISel] Use libcalls for f32/f64 G_FCMP without F/D extensions. (#117660)
LegalizerHelp only supported f128 libcalls and incorrectly assumed that
the destination register for the G_FCMP was s32.
2024-11-26 15:48:49 -08:00
Craig Topper
bb5bbe523d [RISCV][GISel] Support s32/s64 G_FSUB/FDIV/FNEG without F/D extensions.
Use libcalls for G_FSUB/FDIV. Use integer operations for G_FNEG.

Copy most of the IR tests for arithmetic from SelectionDAG.
2024-11-24 18:22:12 -08:00
Craig Topper
213b849c5e [RISCV][GISel] Use libcalls for some FP instructions when F/D aren't present.
This is based on what fails when adding integer only RUN lines to
float-intrinsics.ll and double-intrinsics.ll.

We're still missing a lot of test cases that SelectionDAG has. These
will be added in future patches.
2024-11-23 11:43:14 -08:00
Craig Topper
f84fc44f1a [RISCV][GISel] Make s16->s32 G_ANYEXT/SEXT/ZEXT legal. 2024-11-21 22:45:25 -08:00
Craig Topper
4087b871c5
[RISCV][GISel] Move G_BRJT expansion to legalization (#73711)
Instead of custom selecting a bunch of instructions, we can expand to
generic MIR during legalization.
2024-11-20 13:43:36 -08:00
Craig Topper
eff60d83b0 [RISCV][GISel] Make extended loads and truncating stores with s16 register type and s8 memory type legal.
This addresses some failures I've seen in testing on real code.
2024-11-19 11:57:35 -08:00
Craig Topper
eed9af95e6 [RISCV][GISel] Make loads/stores with s16 register type and s16 memory type legal.
This is needed to support Zfh loads/stores.

This requires supporting extends from sext/zext form i16 and s16
G_FREEZE to support the current tests we have.
2024-11-17 11:39:59 -08:00
Craig Topper
2d95ad0531 [RISCV][GISel] Use boolean predicated legalization action method to simplify code. NFC 2024-11-13 09:21:53 -08:00
Craig Topper
fd8d4333fc [RISCV][GISel] Promote s32 G_SEXTLOAD/ZEXTLOAD on RV64. 2024-11-13 08:08:37 -08:00
Craig Topper
4bd6e15a45 [RISCV][GISel] Sync MaxIterations/ObserverLvl/EnableFullDCE for PreLegalizer combiners with AArch64. 2024-11-12 13:07:51 -08:00