356 Commits

Author SHA1 Message Date
darkbuck
8e98435ae9
[GISel][Combine] Enhance combining on G_BUILD_VECTOR
Reviewers: aemerson, arsenm

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/87831
2024-04-06 18:33:01 -04:00
Amara Emerson
60fc4ac67a [GlobalISel] Don't form anyextending atomic loads.
Until we can reliably check the legality and improve our selection of these,
don't form them at all.
2024-04-05 13:34:59 -07:00
Michael Liao
a1b2f0cc44 Reland "[GlobalISel] Fix the infinite loop issue in commute_int_constant_to_rhs"
- That test needs to disable combine rules by name and hence requires `asserts`.
2024-04-05 10:34:12 -04:00
Gulfem Savrun Yeniceri
be8fd86f6a Revert "[GlobalISel] Fix the infinite loop issue in commute_int_constant_to_rhs"
This reverts commit 1f01c580444ea2daef67f95ffc5fde2de5a37cec
because combine-commute-int-const-lhs.mir test failed in
multiple builders.
https://lab.llvm.org/buildbot/#/builders/124/builds/10375
https://luci-milo.appspot.com/ui/p/fuchsia/builders/prod/clang-linux-x64/b8751607530180046481/overview
2024-04-04 16:39:31 +00:00
Jay Foad
1b761205f2
[APInt] Add a simpler overload of multiplicativeInverse (#87610)
The current APInt::multiplicativeInverse takes a modulus which can be
any value, but all in-tree callers use a power of two. Moreover, most
callers want to use two to the power of the width of an existing APInt,
which is awkward because 2^N is not representable as an N-bit APInt.

Add a new overload of multiplicativeInverse which implicitly uses
2^BitWidth as the modulus.
2024-04-04 16:11:06 +01:00
darkbuck
1f01c58044
[GlobalISel] Fix the infinite loop issue in commute_int_constant_to_rhs
- When both operands are constant, the matcher runs into an infinite
  loop as the commutation should be applied only when LHS is a constant
  and RHS is not.

Reviewers: arsenm

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/87426
2024-04-03 20:52:21 -04:00
Thorsten Schütt
8bb9443333
[GlobalIsel] Combine G_EXTRACT_VECTOR_ELT (#85321)
preliminary steps
2024-04-02 09:01:24 +02:00
Shilei Tian
360f7f5674
[GlobalISel] Call setInstrAndDebugLoc before tryCombineAll (#86993)
This can remove all unnecessary redundant calls in each combiner.
2024-03-29 15:27:28 -04:00
Shilei Tian
661bb9daae
[GlobalISel] Handle div-by-pow2 (#83155)
This patch adds similar handling of div-by-pow2 as in `SelectionDAG`.
2024-03-29 12:41:47 -04:00
Thorsten Schütt
deefe3fbc9
[GlobalIsel] Post-review combine ADDO (#85961)
https://github.com/llvm/llvm-project/pull/82927
2024-03-21 03:56:40 +01:00
David Green
601e102bdb
[CodeGen] Use LocationSize for MMO getSize (#84751)
This is part of #70452 that changes the type used for the external
interface of MMO to LocationSize as opposed to uint64_t. This means the
constructors take LocationSize, and convert ~UINT64_C(0) to
LocationSize::beforeOrAfter(). The getSize methods return a
LocationSize.

This allows us to be more precise with unknown sizes, not accidentally
treating them as unsigned values, and in the future should allow us to
add proper scalable vector support but none of that is included in this
patch. It should mostly be an NFC.

Global ISel is still expected to use the underlying LLT as it needs, and
are not expected to see unknown sizes for generic operations. Most of
the changes are hopefully fairly mechanical, adding a lot of getValue()
calls and protecting them with hasValue() where needed.
2024-03-17 18:15:56 +00:00
Thorsten Schütt
5f774619ea
[GlobalIsel] Combine ADDO (#82927)
Perform the requested arithmetic and produce a carry output in addition
to the normal result.

Clang has them as builtins (__builtin_add_overflow_p). The middle end
has intrinsics for them (sadd_with_overflow).

AArch64: ADDS Add and set flags

On Neoverse V2, they run at half the throughput of basic arithmetic and
have a limited set of pipelines.
2024-03-14 12:45:19 +01:00
Shilei Tian
55d4816393 [NFC] Remove trailing white spaces 2024-03-13 20:18:40 -04:00
Amara Emerson
26fa440957 [GlobalISel] Fix yet another pointer type invalid combining issue, this time in tryFoldSelectOfConstants() 2024-03-07 15:58:28 -08:00
Amara Emerson
641b98a0d1 [GlobalISel] Fix crash in tryFoldAndOrOrICmpsUsingRanges() with pointer types. 2024-03-07 12:56:40 -08:00
Owen Anderson
ebb64d8370
[GlobalISel] Make the Combiner insert G_FREEZE when converting G_SELECT to binary operations. (#82733)
This is needed because the binary operators (G_OR and G_AND) do
not have the poison-suppressing semantics of G_SELECT.

Fixes https://github.com/llvm/llvm-project/issues/72475
2024-02-26 10:50:37 -05:00
Owen Anderson
c02b0d008c
[GlobalISel] Make sure to check for load barriers when merging G_EXTRACT_VECTOR_ELT into G_LOAD. (#82306)
Fixes https://github.com/llvm/llvm-project/issues/78477
2024-02-20 22:42:14 -05:00
David Green
1b12974ccb
[AArch64][AMDGPU][GlobalISel] Remove vector handling from unmerge_dead_to_trunc (#82224)
This combine transforms an unmerge where only the first element is used
into a truncate. That works OK for scalar but for vector needs to insert
a bitcast to integers, perform the truncate then bitcast back to
vectors. This generates more awkward code than using an Unmerge.
2024-02-20 10:54:44 +00:00
Thorsten Schütt
63a4b4f610
[GlobalIsel] Combine logic of floating point compares (#81886)
It is purely based on symmetry. Registers can be scalars, vectors, and
non-constants.

X < 5.0 || X > 5.0
  ->
X != 5.0

X < Y && X > Y
  ->
  FCMP_FALSE

X < Y && X < Y
  ->
  FCMP_TRUE

see InstCombinerImpl::foldLogicOfFCmps
2024-02-20 09:56:33 +01:00
chuongg3
f6f8e202f5
[AArch64][GlobalISel] Refactor Combine G_CONCAT_VECTOR (#80866)
The combine now works using tablegen and checks if new instruction is
legal before creating it.
2024-02-15 10:09:20 +00:00
Thorsten Schütt
364f781344
[GlobalIsel] Combine logic of icmps (#77855)
Inspired by InstCombinerImpl::foldAndOrOfICmpsUsingRanges with some
adaptations to MIR.
2024-02-06 15:58:02 +01:00
Dávid Ferenc Szabó
55172b7005
[GlobalISel] Improve combines for extend operation by taking hint ins… (#74125)
…tructions into account

Hint instructions like G_ASSERT_ZEXT cann be viewed as a copy. Including
this fact into the combiner allows the match more patterns involving
such instructions.
2024-01-17 15:21:02 +07:00
Amara Emerson
eb009ed249 [GlobalISel] Fix the select->minmax combine from trying to operate on pointer types. 2024-01-15 18:20:18 -08:00
Amara Emerson
a946934a12 [GlobalISel][NFC] Use GPhi wrapper in more places instead of iterating over operands. 2024-01-11 22:25:53 -08:00
Emil J
3baedb4111
[GISel] Fix #77762: extend correct source registers in combiner helper rule extend_through_phis (#77765)
Since we already know which register we want to extend, we don't have to
ask its defining MI about it

---------

Co-authored-by: Emil Tywoniak <Emil.Tywoniak@hightec-rt.com>
2024-01-12 12:09:58 +08:00
Thorsten Schütt
d7642b2200
[GlobalIsel] Combine select to integer minmax (second attempt). (#77520)
Instcombine canonicalizes selects to floating point and integer minmax.
This and the dag combiner canonicalize to floating point minmax. None of
them canonicalizes to integer minmax. On Neoverse V2 basic integer
arithmetic and integer minmax have the same costs.
2024-01-11 09:50:33 +01:00
Thorsten Schütt
a085402ef5 Revert "[GlobalIsel] Combine select of binops (#76763)"
This reverts commit 1687555572ee4fb435da400dde02e7a1e60b742c.
2024-01-06 17:04:24 +01:00
Thorsten Schütt
1687555572
[GlobalIsel] Combine select of binops (#76763) 2024-01-06 11:28:10 +01:00
Thorsten Schütt
4b9194952d
[GlobalIsel] Combine selects with constants (#76089)
A first small step at combining selects.
2024-01-02 17:26:39 +01: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
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
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
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
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
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
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
Amara Emerson
985362e2f3
[AArch64][GlobalISel] Avoid running the shl(zext(a), C) -> zext(shl(a, C)) combine. (#67045) 2023-09-22 09:37:52 +08:00
Amara Emerson
eaab3245d4
[GlobalISel] Add constant folding support for G_FMA/G_FMAD in the combiner. (#65659) 2023-09-09 16:32:02 +08:00
Amara Emerson
1cc9f626cb
[GlobalISel] Add constant-folding of FP binops to combiner. (#65230) 2023-09-07 19:33:35 +03:00
Tuan Chuong Goh
b7a305deca [AArch64][GlobalISel] Optimise Combine Funnel Shift
Combine any funnel shift with a shift amount of 0 to a copy.
Modulo is applied to shift amount if it is larger than the
instruction's bitwidth.

Differential Revision: https://reviews.llvm.org/D157591
2023-09-07 11:58:12 +01:00
Vladislav Dzhidzhoev
1d0d2dfce7 [GlobalISel] Fold G_SHUFFLE_VECTOR with a single element mask to G_EXTRACT_VECTOR_ELT
It introduces minor regression in arm64-vcvt_f.ll, which will be fixed
later.
2023-09-07 12:03:04 +02:00
Amara Emerson
6c31f20fee
[GlobalISel] Fold fmul x, 1.0 -> x (#65379) 2023-09-06 03:14:16 +08:00
Amara Emerson
08e04209d8
[GlobalISel] Commute G_FMUL and G_FADD constant LHS to RHS. (#65298) 2023-09-05 23:48:34 +08:00
Amara Emerson
91746d15d2
[GlobalISel] Fix G_PTR_ADD immediate chain combine using the wrong im… (#65271) 2023-09-05 08:06:40 +08:00
Amara Emerson
0065640f40 [GlobalISel] Look through a G_PTR_ADD's def register instead of it's source operand's
uses when looking for load/store users. This was a simple logic bug during translation
of the equivalent function in SelectionDAG:
```
    for (SDNode *Node : N->uses()) {
      if (auto *LoadStore = dyn_cast<MemSDNode>(Node)) {
```
2023-09-04 00:28:57 -07:00
Amara Emerson
1ef1eec8db [GlobalISel][NFC] Use GenericMachineInstrs in CombinerHelper::reassociationCanBreakAddressingModePattern(). 2023-09-03 21:17:31 -07:00
Fangrui Song
111fcb0df0 [llvm] Fix duplicate word typos. NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 18:25:16 -07:00