Commit Graph

2181 Commits

Author SHA1 Message Date
Jon Roelofs
b071b70317 [GlobalISel] Always direct-call IFuncs and Aliases (#74902)
This is safe because for both cases, the use must be in the same TU as the definition, and they cannot be forward declared.
2023-12-14 14:58:20 -07:00
Thorsten Schütt
26616c62d1 [GlobalIsel][NFC] Harden MachineIRBuilder (#75465)
Protective measures against
https://github.com/llvm/llvm-project/pull/74502
2023-12-14 14:04:57 +01:00
Simon Pilgrim
a0c7a29655 [GlobalISel] IRTranslator::translateGetElementPtr - don't assume a gep constant offset is representable as i64
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65052
2023-12-14 11:02:38 +00:00
Jay Foad
35ebd92d3d [GlobalISel] Add G_PREFETCH (#74863) 2023-12-11 11:06:50 +00:00
Michael Maitland
6f9cb9a75c [RISCV][GISEL] Legalize G_VAARG through expansion. (#73065)
G_VAARG can be expanded similiar to SelectionDAG::expandVAArg through
LegalizerHelper::lower. This patch implements the lowering through this
style of expansion.

The expansion gets the head of the va_list by loading the pointer to
va_list. Then, the head of the list is adjusted depending on argument
alignment information. This gives a pointer to the element to be read
out of the va_list. Next, the head of the va_list is bumped to the next
element in the list. The new head of the list is stored back to the
original pointer to the head of the va_list so that subsequent G_VAARG
instructions get the next element in the list. Lastly, the element is
loaded from the alignment adjusted pointer constructed earlier.

This change is stacked on #73062.
2023-12-08 13:24:27 -05:00
Craig Topper
6419fb5167 [GISel] Don't print the opcode twice in LegalityQuery::print. (#74232) 2023-12-06 13:45:53 -08:00
Jie Fu
a8d5f731d6 [GlobalISel] Remove unused variable 'ResultTy' in CombinerHelper.cpp (NFC)
llvm-project/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:1179:7:
 error: unused variable 'ResultTy' [-Werror,-Wunused-variable]
  LLT ResultTy = MRI.getType(MI.getOperand(0).getReg());
      ^
1 error generated.
2023-12-06 14:08:07 +08:00
Pranav Taneja
41507fe595 [GISel] Combine (Scalarize) vector load followed by an element extract. 2023-12-06 11:23:23 +05:30
Craig Topper
d605d9d7a1 [RISCV][GISel] Support G_ROTL/G_ROTR with Zbb. (#72825) 2023-12-04 13:00:34 -08:00
Momchil Velikov
c1140d49ec [AArch64] Stack probing for dynamic allocas in GlobalISel (#67123)
Co-authored-by: Oliver Stannard <oliver.stannard@linaro.org>
2023-12-04 09:44:02 +00:00
Craig Topper
755c28a940 [GISel][Mips] Infer alignment when creating memory operand for G_VASTART. (#74004) 2023-11-30 19:55:23 -08:00
Youngsuk Kim
d8b8aa3a56 [llvm] Replace calls to Type::getPointerTo (NFC)
Cleanup work towards removing the method Type::getPointerTo.

If a call to Type::getPointerTo is used solely to support an unneeded
pointer-cast, remove the call entirely.
2023-11-27 10:49:34 -06:00
David Green
295edaab13 [AArch64][GlobalISel] Better vecreduce.fadd lowering. (PR #73294)
This changes the fadd legalization to handle fp16 types, and treats more types
as legal so that the backend can produce the correct patterns. This is
currently a missing identity fold for `fadd x -0.0 -> x`
2023-11-27 08:20:54 +00:00
Antonio Frighetto
0ff5281c94 [GlobalISel] Treat shift amounts as unsigned in matchShiftImmedChain
A miscompilation issue in the GISel pre-legalization
phase has been addressed with improved routines.

Fixes: https://github.com/llvm/llvm-project/issues/71440.
2023-11-24 18:14:52 +01:00
Craig Topper
5d501b1091 [GISel][RISCV] Fix several boundary cases in narrow G_SEXT_INREG. (#72719)
This fixes cases when SizeInBits is a multiple of the narrow size.

If SizeBits is equal to NarrowTy size, the first block would create an
illegal G_SEXT_INREG where the the extension size is equal to the type.
I tried to turn it into G_TRUNC+G_SEXT, but that just turned back into
G_SEXT_INREG causing an infinite loop. So punt to the splitting case.

In the for loop we should copy when the part ends on SizeInBits. In that
case there is no G_SEXT_INREG needed for partial. But we should note
that register in PartialExtensionReg for the first full part to use.

If the part starts on SizeInBits then we should do an AShr of
PartialExtensionReg.

We should only get to the G_SEXT_INREG case if the SizeInBits is in the
middle of the part.
2023-11-24 08:39:38 -08:00
Min-Yih Hsu
7c3c8a1277 [RISCV][GISel] Add support for G_IS_FPCLASS in F and D extensions (#72000)
Add legalizer, regbankselect, and isel supports for floating point
version of G_IS_FPCLASS.
2023-11-22 16:43:20 -08:00
Sander de Smalen
81b7f115fb [llvm][TypeSize] Fix addition/subtraction in TypeSize. (#72979)
It seems TypeSize is currently broken in the sense that:

  TypeSize::Fixed(4) + TypeSize::Scalable(4) => TypeSize::Fixed(8)

without failing its assert that explicitly tests for this case:

  assert(LHS.Scalable == RHS.Scalable && ...);

The reason this fails is that `Scalable` is a static method of class
TypeSize,
and LHS and RHS are both objects of class TypeSize. So this is
evaluating
if the pointer to the function Scalable == the pointer to the function
Scalable,
which is always true because LHS and RHS have the same class.

This patch fixes the issue by renaming `TypeSize::Scalable` ->
`TypeSize::getScalable`, as well as `TypeSize::Fixed` to
`TypeSize::getFixed`,
so that it no longer clashes with the variable in
FixedOrScalableQuantity.

The new methods now also better match the coding standard, which
specifies that:
* Variable names should be nouns (as they represent state)
* Function names should be verb phrases (as they represent actions)
2023-11-22 08:52:53 +00:00
HaohaiWen
394bba766d [CodeGen][DebugInfo] Add missing debug info for jump table BB (#71021)
visitJumpTable is called on FinishBasicBlock. At that time, getCurSDLoc
will always return SDLoc without DebugLoc since CurInst was set to
nullptr after visiting each instruction.
This patch passes SDLoc to buildJumpTable when visiting SwitchInst so
that visitJumpTable can use it later.
2023-11-18 19:17:51 +08:00
Michael Maitland
725e599637 [RISCV][GISEL] Add support for scalable vector types in lowerReturnVal (#71587)
Scalable vector types from LLVM IR are lowered into physical vector
registers in MIR based on calling convention for return instructions.
2023-11-15 17:30:53 -05:00
Changpeng Fang
011c9eeb9a GlobalISel: Guard return in llvm::getIConstantSplatVal (#71989)
getIConstantVRegValWithLookThrough could return NULL.
2023-11-14 12:23:54 -08:00
Michael Maitland
a7bbcc4690 [RISCV][GISEL] Add support for lowerFormalArguments that contain scalable vector types (#70882)
Scalable vector types from LLVM IR can be lowered to scalable vector
types in MIR according to the RISCVAssignFn.
2023-11-14 13:15:41 -05:00
Acim-Maravic
f3138524db [AMDGPU] Generic lowering for rint and nearbyint (#69596)
The are three different rounding intrinsics, that are brought down to
same instruction.

Co-authored-by: Acim Maravic <acim.maravic@amd.com>
2023-11-14 18:49:21 +01:00
Craig Topper
44e8bea400 [GISel][AArch64] Notify the Observer when CTTZ lowering changes the opcode to CTPOP. (#72008) 2023-11-12 19:36:24 -08:00
David Green
10ce319320 [AArch64][GlobalISel] Expand handling for sitofp and uitofp (#71282)
Similar to #70635, this expands the handling of integer to fp
conversions. The code is very similar to the float->integer conversions
with types handled oppositely. There are some extra unhandled cases
which require more handling for ASR operations.
2023-11-10 13:41:13 +00:00
Paulo Matos
7b9d73c2f9 [NFC] Remove Type::getInt8PtrTy (#71029)
Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
2023-11-07 17:26:26 +01:00
Amara Emerson
6b69584660 [GlobalISel] Fall back for bf16 conversions. (#71470)
We don't support these correctly since we don't yet have FP types.
AMDGPU tests were silently miscompiling bf16 as if they were fp16.
2023-11-06 21:18:57 -08:00
Diana
7f5d59b38d [AMDGPU] ISel for @llvm.amdgcn.cs.chain intrinsic (#68186)
The @llvm.amdgcn.cs.chain intrinsic is essentially a call. The call
parameters are bundled up into 2 intrinsic arguments, one for those that
should go in the SGPRs (the 3rd intrinsic argument), and one for those
that should go in the VGPRs (the 4th intrinsic argument). Both will
often be some kind of aggregate.

Both instruction selection frameworks have some internal representation
for intrinsics (G_INTRINSIC[_WITH_SIDE_EFFECTS] for GlobalISel,
ISD::INTRINSIC_[VOID|WITH_CHAIN] for DAGISel), but we can't use those
because aggregates are dissolved very early on during ISel and we'd lose
the inreg information. Therefore, this patch shortcircuits both the
IRTranslator and SelectionDAGBuilder to lower this intrinsic as a call
from the very start. It tries to use the existing infrastructure as much
as possible, by calling into the code for lowering tail calls.

This has already gone through a few rounds of review in Phab:

Differential Revision: https://reviews.llvm.org/D153761
2023-11-06 12:30:07 +01:00
Craig Topper
16ddd25b69 Revert "[GISel] Add LookThroughInstrs for getIConstantVRegVal and getIConstan… (#68327)"
This reverts commit 28ae42e662.

The assert in getIConstantVRegVal was not updated for this change.
The ValAndVReg->VReg == VReg check fails if any look through happens.

RISC-V was the only target using the lookthrough functionality, but I'm
not sure it was needed so I'm removing that too.
2023-11-04 12:21:06 -07:00
David Green
54574d3272 [AArch64][GlobalISel] Expand handling for fptosi and fptoui (#70635)
Now that we have more types handled for zext/sext and trunc, it is
possible to get more types working for the vector float to integer
conversions. This patch adds fp16, widening and narrowing vector support
to handle more types. The smaller types wil be expanded to the size of
the larger element type. A couple of case require more awkward truncates
to get working as they go from illegal to illegal types.
2023-11-04 11:47:05 +00:00
Tobias Stadler
373c343a77 Reland: [GlobalISel] LegalizationArtifactCombiner: Elide redundant G_AND
Reland 3686a0b after fixing an exposed miscompile in #68840

Differential Revision: https://reviews.llvm.org/D159140
2023-11-02 00:18:19 +01:00
Pierre van Houtryve
b26e6a8eb5 [GlobalISel] Add GITypeOf special type (#66079)
Allows creating a register/immediate that uses the same type as a
matched operand.
2023-10-31 09:57:10 +01:00
Michael Maitland
04dd2ac03a [RISCV][GlobalISel] Select G_GLOBAL_VALUE (#70091)
G_GLOBAL_VALUE should be lowered into an absolute address if
`-codemodel=small` is used or into a PC-relative if `-codemodel=medium`
is used.

PR #68380 tried to create special instructions to do this, but I don't
see why we need to do that.
2023-10-30 15:46:36 -04:00
Amara Emerson
93659947d2 [AArch64][GlobalISel] Add support for pre-indexed loads/stores. (#70185)
The pre-index matcher just needs some small heuristics to make sure it
doesn't cause regressions. Apart from that it's a simple change, since
the only difference is an immediate operand of '1' vs '0' in the
instruction.
2023-10-26 10:29:12 -07:00
Craig Topper
2f4328e697 [GISel] Make assignValueToReg take CCValAssign by const reference. (#70086)
This was previously passed by value. It used to be passed by non-const
reference, but it was changed to value in D110610. I'm not sure why.
2023-10-24 15:47:04 -07:00
Amara Emerson
1b11729dc0 [AArch64][GlobalISel] Add support for post-indexed loads/stores. (#69532)
Gives small code size improvements across the board at -Os CTMark.

Much of the work is porting the existing heuristics in the DAGCombiner.
2023-10-24 13:51:59 -07:00
Craig Topper
9f592cbc18 [GISel] Pass MPO and VA to assignValueToAddress by const reference. NFC (#69810)
Previously they were passed by non-const reference. No in tree target
modifies the values.

This makes it possible to call assignValueToAddress from
assignCustomValue without a const_cast. For example in this patch
https://github.com/llvm/llvm-project/pull/69138.
2023-10-24 09:58:22 -07:00
Michael Maitland
28ae42e662 [GISel] Add LookThroughInstrs for getIConstantVRegVal and getIConstan… (#68327)
…tVRegSExtVal

The implementation of these methods uses
getIConstantVRegValWithLookThrough with LookThroughInstrs argument set
to false. By adding the optional argument to getIConstantVRegVal and
getIConstantVRegSExtVal we can take advantage of the already built look
through functionality.
2023-10-20 17:52:39 -04:00
Craig Topper
3750558ee1 [RISCV][GISel] Legalize G_SMULO/G_UMULO (#67635)
Update `LegalizerHelper::widenScalarMulo` to not create a mulo if we aren't going to use the overflow flag. This prevents needing to legalize the widened operation. This generates better code when we need to make a libcall for multiply.
2023-10-13 20:34:45 -07:00
chuongg3
d88d9834e9 [AArch64][GlobalISel] Support more types for TRUNC (#66927)
G_TRUNC will get lowered into trunc(merge(trunc(unmerge),
trunc(unmerge))) if the source is larger than 128 bits or the truncation
is more than half of the current bit size.

Now mirrors ZEXT/SEXT code more closely for vector types.
2023-10-11 16:05:25 +01:00
Serge Pavlov
462d5830da [GlobalISel] Add support for *_fpmode intrinsics
The change implements support of the intrinsics `get_fpmode`,
`set_fpmode` and `reset_fpmode` in Global Instruction Selector. Now they
are lowered into library function calls.

Differential Revision: https://reviews.llvm.org/D158260
2023-10-09 21:14:07 +07:00
Matthias Braun
5181156b37 Use BlockFrequency type in more places (NFC) (#68266)
The `BlockFrequency` class abstracts `uint64_t` frequency values. Use it
more consistently in various APIs and disable implicit conversion to
make usage more consistent and explicit.

- Use `BlockFrequency Freq` parameter for `setBlockFreq`,
`getProfileCountFromFreq` and `setBlockFreqAndScale` functions.
- Return `BlockFrequency` in `getEntryFreq()` functions.
- While on it change some `const BlockFrequency& Freq` parameters to
plain `BlockFreqency Freq`.
- Mark `BlockFrequency(uint64_t)` constructor as explicit.
- Add missing `BlockFrequency::operator!=`.
- Remove `uint64_t BlockFreqency::getMaxFrequency()`.
- Add `BlockFrequency BlockFrequency::max()` function.
2023-10-05 11:40:17 -07:00
JOE1994
204883623e [NFC] Replace uses of Type::getPointerTo
Replace some uses of `Type::getPointerTo` via 2 ways
* Remove entirely if it's only used to support an unnecessary bitcast
  (remove the bitcast as well).
* Replace with `PointerType::get`/`PointerType::getUnqual`

NFC opaque pointer clean-up effort.
2023-09-29 21:38:53 -04:00
Tobias Stadler
305fbc1b32 Revert "[GlobalISel] LegalizationArtifactCombiner: Elide redundant G_AND"
This reverts commit 3686a0b611.
This seems to have broken some sanitizer tests:
https://lab.llvm.org/buildbot/#/builders/184/builds/7721
2023-09-29 03:35:40 +02:00
Tobias Stadler
3686a0b611 [GlobalISel] LegalizationArtifactCombiner: Elide redundant G_AND
The legalizer currently generates lots of G_AND artifacts.
For example between boolean uses and defs there is always a G_AND with a mask of 1, but when the target uses ZeroOrOneBooleanContents, this is unnecessary.
Currently these artifacts have to be removed using post-legalize combines.
Omitting these artifacts at their source in the artifact combiner has a few advantages:
- We know that the emitted G_AND is very likely to be useless, so our KnownBits call is likely worth it.
- The G_AND and G_CONSTANT can interrupt e.g. G_UADDE/... sequences generated during legalization of wide adds which makes it harder to detect these sequences in the instruction selector (e.g. useful to prevent unnecessary reloading of AArch64 NZCV register).
- This cleans up a lot of legalizer output and even improves compilation-times.
AArch64 CTMark geomean: `O0` -5.6% size..text; `O0` and `O3` ~-0.9% compilation-time (instruction count).

Since this introduces KnownBits into code-paths used by `O0`, I reduced the default recursion depth.
This doesn't seem to make a difference in CTMark, but should prevent excessive recursive calls in the worst case.

Reviewed By: aemerson

Differential Revision: https://reviews.llvm.org/D159140
2023-09-29 02:11:57 +02:00
Jay Foad
21c2ba4bdb [GlobalISel] Remove TargetLowering::isConstantUnsignedBitfieldExtractLegal
Use LegalizerInfo::isLegalOrCustom instead.

Differential Revision: https://reviews.llvm.org/D116807
2023-09-27 15:58:01 +01:00
Amara Emerson
ea7157ff4f [GlobalISel] Propagate mem operands for indexed load/stores.
There isn't a test for this yet since the combines aren't used atm, but it will
be tested as part of a future commit. I'm just making this a separate change
tidyness reasons.
2023-09-25 14:41:20 -07:00
Nick Desaulniers
330fa7d2a4 [TargetLowering] Deduplicate choosing InlineAsm constraint between ISels (#67057)
Given a list of constraints for InlineAsm (ex. "imr") I'm looking to
modify the order in which they are chosen. Before doing so, I noticed a
fair
amount of logic is duplicated between SelectionDAGISel and GlobalISel
for this.

That is because SelectionDAGISel is also trying to lower immediates
during selection. If we detangle these concerns into:
1. choose the preferred constraint
2. attempt to lower that constraint

Then we can slide down the list of constraints until we find one that
can be lowered. That allows the implementation to be shared between
instruction selection frameworks.

This makes it so that later I might only need to adjust the priority of
constraints in one place, and have both selectors behave the same.
2023-09-25 08:53:03 -07:00
Amara Emerson
7e5c2672cb [GlobalISel][NFC] Clean up and modernize the indexed load/store combines.
Use wrappers and helpers to tidy it up, and remove some debug prints.
2023-09-25 00:32:36 -07:00
Amara Emerson
bc6e7f0573 [GlobalISel][NFC] Remove unused method CombinerHelper::tryCombine()
The combines were ported to the tablegen combiner a long time ago so this
manual method isn't needed.
2023-09-24 22:20:21 +08:00
Kazu Hirata
ce8c22856e Use llvm::drop_begin and llvm::drop_end (NFC) 2023-09-22 17:29:10 -07:00