10232 Commits

Author SHA1 Message Date
vangthao95
87bec47152
AMDGPU/GlobalISel: RegBankLegalize rules for div_fmas/fixup/scale (#188305) 2026-03-27 10:10:09 -07:00
Marina Taylor
55322f2d43
[ObjCARC] Run ObjCARCContract before PreISelIntrinsicLowering (#184149)
74e4694 moved ObjCARCContract from running before the codegen pipeline
into addISelPrepare(), which runs after PreISelIntrinsicLowering.

This broke ObjCARCContract's retainRV-to-claimRV optimization because
ObjCARCContract identifies ARC calls via intrinsics, not their lowered
counterparts.

This patch restores the pre-74e4694 ordering by moving ObjCARCContract
to addISelPasses.

The IntrinsicInst.cpp change looks extraneous but is required here:
ObjCARCContract may now rewrite the bundle operand from retainRV to
claimRV. When PreISelIntrinsicLowering then encounters this new
intrinsic use, lowerObjCCall asserts mayLowerToFunctionCall.

Assisted-by: claude

rdar://137997453
2026-03-27 15:37:47 +00:00
Matt Arsenault
dba3de54a2
AMDGPU: Allow poison vector elts in fract pattern (#188991) 2026-03-27 13:59:28 +00:00
Matt Arsenault
fc2dac83ed
AMDGPU: Fold frame indexes into disjoint s_or_b32 (#102345)
Some pointer adds get turned into ors, and sometimes and is
performed on pointers for masking.
2026-03-27 13:13:48 +01:00
Osama Abdelkader
0959a2a4bd
Enable generic overlapping optimization for memmove (#177885)
Fixes: #165948
2026-03-27 07:22:05 +00:00
Anshil Gandhi
3833f03054
[AMDGPU][GlobalISel] Add RegBankLegalize rules for amdgcn_perm intrinsic (#187798)
Add uniform and divergent register bank legalization rules for the amdgcn_perm intrinsic (v_perm_b32). Since this is a VALU-only instruction, the uniform case maps the destination to UniInVgprB32 and all source operands to VgprB32.
2026-03-27 00:03:32 +00:00
Anshil Gandhi
966d96942a
[AMDGPU][GlobalISel] Add RegBankLegalize rules for amdgcn_permlane64 (#187840)
Add register bank legalization rules for the amdgcn_permlane64 intrinsic
in the new RegBankLegalize framework.

After GISel legalization, permlane64 always operates on S32 — sub-32-bit
types are anyext'd to S32 and types wider than 32 bits are split into
S32 parts by legalizeLaneOp. Add rules for B32 type.

Also enable -new-reg-bank-select in the permlane64 lit test and update
affected check lines.
2026-03-26 23:43:41 +00:00
vangthao95
b9b87dd796
AMDGPU/GlobalISel: RegBankLegalize rules for buffer atomics (#187550)
Add RegBankLegalize rules for the buffer atomics and/xor/or/inc/dec.
2026-03-26 16:28:37 -07:00
Matt Arsenault
67ea4de3c6
AMDGPU: Regenerate test checks (#188862) 2026-03-26 22:48:52 +00:00
vangthao95
29886a1494
AMDGPU/GlobalISel: RegBankLegalize rules for ds_permute (#188266) 2026-03-26 15:24:50 -07:00
Changpeng Fang
df71894094
[AMDGPU] Do not overlap dst with srcs for v_cvt_scalef32_2xpk16_fp6/bf6_f32 (#188809)
v_cvt_scalef32_2xpk16_fp6_f32 and v_cvt_scalef32_2xpk16_bf6_f32, as multipass instructions,
the destination operand must not overlap with any of the source operands.
In this work, we apply Constraints = "@earlyclobber $vdst" to these two instructions.

Fixes: LCCOMPILER-561
2026-03-26 14:38:22 -07:00
134ARG
331c1c0b84
[ValueTracking] Refine SIToFP/UIToFP FPClass inference with KnownBits (#187185)
This patch propagates the KnownBits of the source integer to improve
floating-point class inference for sitofp and uitofp instructions.

Specifically,
1. The result is never -0.0.
2. The result is not +0.0 if the source integer is known non-zero.
3. The result is not negative if the source integer is known
non-negative (or for uitofp).
4. The result is not Infinity if the largest possible integer magnitude
fits within the target FP type's exponent limits.

alive2 results for added testcases:
testcase 1: https://alive2.llvm.org/ce/z/eM34LB
testcase 2: https://alive2.llvm.org/ce/z/ext7XF 
testcase 3: https://alive2.llvm.org/ce/z/g8yb6q
testcase 4: https://alive2.llvm.org/ce/z/cyFYRy
testcase 5: https://alive2.llvm.org/ce/z/LePFrm

alive2 for updated testcase in binop-itofp:

updated 1: https://alive2.llvm.org/ce/z/KPQ5bZ
udpated 2: https://alive2.llvm.org/ce/z/bGf43t
updated 3: https://alive2.llvm.org/ce/z/YKnCwU
updaetd 4: https://alive2.llvm.org/ce/z/mqKaq-
updated 5: https://alive2.llvm.org/ce/z/jYSAB5

Fix #186952
2026-03-26 18:14:58 +01:00
Syadus Sefat
5f5f330ee4
[AMDGPU][GlobalIsel] Add register bank legalization rules for amdgcn_interp_inreg (#187248)
This patch adds register bank legalization rules for amdgcn_interp_inreg
operations in the AMDGPU GlobalISel pipeline.
2026-03-26 11:55:17 -05:00
Dmitry Sidorov
76f88063b6
[AMDGPU] Remove AMDGPUISD::FFBH_I32 and add ISD::CTLS lowering (#187694)
It's the a continuation of previously reverted
https://github.com/llvm/llvm-project/pull/178420

The patch removes custom AMDGPUISD::FFBH_I32 SelectionDAG node. Call
sites that need raw hardware semantics (LowerINT_TO_FP32, legalizeITOFP)
now use amdgcn_sffbh intrinsic directly. ISD::CTLS is added as a Custom
operation for i32.

Previous attempt had an issue:
The hardware v_ffbh_i32 instruction (v_cls_i32 on newer targets) has
different semantics than ISD::CTLS:
-sffbh returns [1, BitWidth-1] for normal values, -1 for
all-same-bits
-CTLS returns [0, BitWidth-2] for normal values, BitWidth-1 for
all-same-bits

Now LowerCTLS handles this by: sffbh -> umin(sffbh, BitWidth) -> sub 1.

Current patch also adds DAG combine to recognize the common CTLS idiom:
sub(ctlz(xor(x, sra(x, BitWidth-1))), 1) -> ctls(x)
and an optimization in performMinMaxCombine to fold away umin
when the input is not all-same-bits.

Partially addresses #177635
2026-03-26 16:14:34 +01:00
Anshil Gandhi
4140ea18f5
[AMDGPU][GlobalISel] Add RegBankLegalize rules for permlane16_var/permlanex16_var (#187806)
Add register bank legalize rules for the amdgcn_permlane16_var and
amdgcn_permlanex16_var intrinsics. All register operands (result, old,
src0, src1) map to VGPR since these are VALU lane permutation
operations.

Enable -new-reg-bank-select in the permlane16.var test.
2026-03-26 10:07:40 -04:00
Jay Foad
2f15e4ea33
[AMDGPU] Remove redundant S_WAIT_XCNT after inserting S_SET_VGPR_MSB (#188527) 2026-03-26 10:59:26 +00:00
sstipano
d913726dd6
[AMDGPU] Don't allow nesting hard clauses. (#188460) 2026-03-26 11:47:35 +01:00
Stanislav Mekhanoshin
e69c7312f3
[AMDGPU] Disable neg_lo[0:1] and neg_hi[0:1] on wmma_f32_16x16x32_bf16 (#188649)
This is the pilot change, the rest will follow the same idea.
2026-03-26 00:37:05 -07:00
Ruiling, Song
28497b7e43
AMDGPU: Make VarIndex a WeakVH in AMDGPUPromoteAlloca (#188662)
The VarIndex might come from (like load) another alloca which maybe
promoted before. The value will replaced in this case. WeakVH correctly
handles this.
2026-03-26 13:59:28 +08:00
vangthao95
93311617bf
AMDGPU/GlobalISel: RegBankLegalize rules for s_memrealtime (#188311) 2026-03-25 14:35:21 -07:00
Guo Chen
5509dda003
[AMDGPU][True16] turn on true16 for gfx12 (#187514)
Turn on gfx12 true16 mode as default
2026-03-25 17:25:56 -04:00
Guo Chen
c1251ad58b
[AMDGPU][True16] Generate correct reg size for reg_sequence16 in wmma src mod select (#187629)
When a f16 from a true16 insts is passed to a wmma, the src mod try to
pack it to a v4f16 using v_perm_b32. In true16 mode this is causing an
issue since v_perm_b32 takes vgpr32. Create a vgpr_32 for 16-bit src
before passing to v_perm_b32 in true16 mode so that the reg size
matched.

Ideailly we should use reg_sequence to replace v_perm_b32 in true16
mode. However, it currently hit a problem with bad code quality. With
current optimization it only shows better code quality when .hi16 is
selected in vector shuffle. Will fix it when reg allocator and coalescer
can reduce the extra mov
2026-03-25 14:59:05 -04:00
vangthao95
8491df6c8c
AMDGPU/GlobalISel: RegBankLegalize rules for trig_preop (#188312) 2026-03-25 09:12:45 -07:00
vangthao95
3dd98b7423
AMDGPU/GlobalISel: RegBankLegalize rules for reloc_constant (#188315) 2026-03-25 09:11:01 -07:00
vangthao95
69f9ff6c19
AMDGPU/GlobalISel: RegBankLegalize rules for wqm_demote (#188288) 2026-03-25 09:10:28 -07:00
Owen Anderson
ca9ac0e24a
[CHERI] Allow @llvm.returnaddress to return a pointer in any address space. (#188464)
Clang now constructs calls to it using the default program address space from the DataLayout.

Co-authored-by: Alex Richardson <alexrichardson@google.com>
2026-03-25 13:59:38 +00:00
Petar Avramovic
2f38a8fc57
AMDGPU: Codegen for v_dual_dot2acc_f32_f16/bf16 from VOP3 (#179226)
For V_DOT2_F32_F16 and V_DOT2_F32_BF16 add their VOPDName and mark
them with usesCustomInserter which will be used to add pre-RA register
allocation hints to preferably assign dst and src2 to the same physical
register. When the hint is satisfied, canMapVOP3PToVOPD recognises the
instruction as eligible for VOPD pairing by checking if it is VOP2 like:
dst==src2, no source modifiers, no clamp, and src1 is a register.
Mark both instructions as commutable to allow a literal in src1 to be
moved to src0, since VOPD only permits a literal in src0.
2026-03-25 11:47:07 +01:00
Matt Arsenault
34ee487775
AMDGPU: Implememt memsize forms of isLoadFromStackSlot/isStoreToStackSlot (#188264)
Requested in #182673, though I'm not sure why this needs to be pushed
into targets. The size can be taken from the machine mem operand
generically.
2026-03-25 09:22:04 +01:00
Ruiling, Song
d69fc653c1
AMDGPU: Simplify placeholder replacement in AMDGPUPromoteAlloca (#188202)
If `promoteAllocaUserToVector` returns the placeholder, it means the
instruction does not actually modify the alloca. we don't need to add
the placeholder as block available value for correctness. Instructions
appear afterwards in the the same block could still get the placeholder
as source value through GetCurVal() call. Instructions in other block
which access the alloca will be set up later when we really do
placeholder replacement.

This help simplify the placeholder replacement logic.
2026-03-25 15:26:44 +08:00
zGoldthorpe
11bc6e8776
[SelectionDAG] Add known bit for ISD::FABS (#188335)
Absolute value always clears the sign bit, so make that knowh to
selectionDAG's `computeKnownBits`.
2026-03-24 14:53:06 -06:00
Guo Chen
e71da01f0f
[AMDGPU][True16] add true16 pattern for cvt_pk_fp32_f8 (#180096) 2026-03-24 15:03:00 -04:00
vangthao95
ca2bc5505c
AMDGPU/GlobalISel: RegBankLegalize rules for ps_live (#188101) 2026-03-24 10:08:40 -07:00
vangthao95
9708da6f2d
AMDGPU/GlobalISel: RegBankLegalize rules for fmad_ftz (#188132) 2026-03-24 08:08:23 -07:00
vangthao95
1034c70772
AMDGPU/GlobalISel: RegBankLegalize rules for cvt_pknorm (#187834) 2026-03-24 08:06:51 -07:00
vangthao95
20e59c8e2d
AMDGPU/GlobalISel: RegBankLegalize rules for cube intrinsics (#187762)
Add RegBankLegalize rules for cube* intrinsics. Also update manual tests
to use autogenerated checks.
2026-03-24 08:05:36 -07:00
Carl Ritson
65b576d2b0
[AMDGPU] Disable atomic optimizer for single lane execution (#187915)
Optimized IR will have worse performance when only a single lane is
active. Disable optimizer when single lane is expected at compile time.
2026-03-24 17:59:46 +09:00
Ruiling, Song
c378b79c14
Revert "AMDGPU: Delay value replacement in PromoteAlloca (#186944)" (#188180)
This reverts commit 5624cce586c74ec7cfcbd0243f65cb1870677af7.

This is causing libclc failure. revert to fix it properly.
2026-03-24 06:42:28 +00:00
Ruiling, Song
5624cce586
AMDGPU: Delay value replacement in PromoteAlloca (#186944)
When we do alloca promotion, there might be cross references to the
values derived from different allocas. RAUW immediately during promotion
may fail to update the values cached in the AllocaAnalysis structure.

Solving the problem by postpone the value replacement, and also the
value deletion as well to make this possible.
2026-03-24 08:31:46 +08:00
vangthao95
2bee958599
[AMDGPU][NFC] Update test to use update_llc_test_checks (#188102)
Also add globalisel run lines.

Precommit test for https://github.com/llvm/llvm-project/pull/187834.
2026-03-23 14:17:23 -07:00
vangthao95
22977fd99e
[AMDGPU][NFC] Update permute tests to use auto-generated checks (#188107)
Also add global-isel run line.
2026-03-23 13:29:38 -07:00
Austin Kerbow
89503bda38
[AMDGPU] Add structural stall heuristic to scheduling strategies (#169617)
Implements a structural stall heuristic that considers both resource
hazards and latency constraints when selecting instructions. In coexec,
this changes the pending queue from a binary “not ready to issue”
distinction into part of a unified candidate comparison. Pending
instructions still identify structural stalls in the current cycle, but
they are now evaluated directly against available instructions by stall
cost, making the heuristics both more intuitive and more expressive.

- Add getStructuralStallCycles() to GCNSchedStrategy that computes the
number of cycles an instruction must wait due to:
  - Resource conflicts on unbuffered resources (from the SchedModel)
  - Sequence-dependent hazards (from GCNHazardRecognizer)

- Add getHazardWaitStates() to GCNHazardRecognizer that returns the
number
of wait states until all hazards for an instruction are resolved,
providing cycle-accurate hazard information for scheduling heuristics.
2026-03-23 11:33:43 -07:00
vangthao95
d2e70414b6
AMDGPU/GlobalISel: RegBankLegalize rules for live_mask (#187833) 2026-03-23 11:01:46 -07:00
Anshil Gandhi
94239b3450
[AMDGPU][GlobalISel] Add RegBankLegalize rules for permlane16/permlanex16 (#187906)
Add RegBankLegalize rules for the amdgcn_permlane16
and amdgcn_permlanex16 intrinsics. Both intrinsics
are sources of divergence, so only the divergent
case is needed: result, old, and src0 map to VGPR,
while src1 and src2 are SGPR with ReadFirstLane if
divergent.

Update the GISEL RUN lines in llvm.amdgcn.permlane.ll
and permlane16_opsel.ll to use -new-reg-bank-select,
and regenerate check lines. The v8i16 test cases now
produce identical SDAG/GISEL output so their checks
are unified.
2026-03-23 16:58:05 +00:00
Austin Kerbow
3e4efe3ed4
[AMDGPU] Add ML-oriented coexec scheduler selection and queue handling (#169616)
This patch adds the initial coexec scheduler scaffold for machine
learning workloads on gfx1250.

It introduces function and module-level controls for selecting the
AMDGPU preRA and postRA schedulers, including an `amdgpu-workload-type`
module flag that maps ML workloads to coexec preRA scheduling and a nop
postRA scheduler by default.

It also updates the coexec scheduler to use a simplified top-down
candidate selection path that considers both available and pending
queues through a single flow, setting up follow-on heuristic work.
2026-03-23 09:30:01 -07:00
vangthao95
27adb8f7ad
AMDGPU/GlobalISel: RegBankLegalize rules for exp_compr (#187822)
This intrinsic only accepts vectorTy. Correct the test to use v2s16.
2026-03-23 09:14:24 -07:00
vangthao95
0e0dc535d1
AMDGPU/GlobalISel: Use B32 for readfirstlane (#187809)
Using B32 would also add missing pointer support to readfirstlane
intrinsic rule.
2026-03-23 09:04:49 -07:00
Petar Avramovic
ce5a1dffa2
AMDGPU: Improve codegen for VOP2 v_dot2c_f32_f16/bf16 (#179225)
Select VOP2 version when there are no src_modifers, otherwise VOP3.
2026-03-23 16:55:53 +01:00
vangthao95
0748515784
AMDGPU/GlobalISel: RegBankLegalize rules for mov_dpp (#187807) 2026-03-23 08:53:30 -07:00
Petar Avramovic
034054431d
AMDGPU: Fix src2_modifiers for v_dot2_f32_f16/bf16 (#179224) 2026-03-23 15:44:09 +01:00
Anshil Gandhi
256a4e03b7
[AMDGPU][GlobalISel] Add RegBankLegalize rules for permlane16_swap/permlane32_swap (#187810)
Add register bank legalize rules for the amdgcn_permlane16_swap and
amdgcn_permlane32_swap intrinsics. Both results and both source register
operands map to VGPR since these are VALU lane swap operations.

Enable -new-reg-bank-select in the permlane16.swap and permlane32.swap
tests.
2026-03-23 10:06:51 -04:00