1//=- AMDGPUCombine.td - Define AMDGPU Combine Rules ----------*- tablegen -*-=//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9include "llvm/Target/GlobalISel/Combine.td"
10
11// TODO: This really belongs after legalization after scalarization.
12// TODO: GICombineRules should accept subtarget predicates
13
14def fmin_fmax_legacy_matchdata : GIDefMatchData<"AMDGPUPostLegalizerCombinerHelper::FMinFMaxLegacyInfo">;
15
16def fcmp_select_to_fmin_fmax_legacy : GICombineRule<
17  (defs root:$select, fmin_fmax_legacy_matchdata:$matchinfo),
18  (match (wip_match_opcode G_SELECT):$select,
19         [{ return PostLegalizerHelper.matchFMinFMaxLegacy(*${select}, ${matchinfo}); }]),
20  (apply [{ PostLegalizerHelper.applySelectFCmpToFMinToFMaxLegacy(*${select}, ${matchinfo}); }])>;
21
22
23def uchar_to_float : GICombineRule<
24  (defs root:$itofp),
25  (match (wip_match_opcode G_UITOFP, G_SITOFP):$itofp,
26         [{ return PostLegalizerHelper.matchUCharToFloat(*${itofp}); }]),
27  (apply [{ PostLegalizerHelper.applyUCharToFloat(*${itofp}); }])>;
28
29def cvt_f32_ubyteN_matchdata : GIDefMatchData<"AMDGPUPostLegalizerCombinerHelper::CvtF32UByteMatchInfo">;
30
31def cvt_f32_ubyteN : GICombineRule<
32  (defs root:$cvt_f32_ubyteN, cvt_f32_ubyteN_matchdata:$matchinfo),
33  (match (wip_match_opcode G_AMDGPU_CVT_F32_UBYTE0,
34                           G_AMDGPU_CVT_F32_UBYTE1,
35                           G_AMDGPU_CVT_F32_UBYTE2,
36                           G_AMDGPU_CVT_F32_UBYTE3):$cvt_f32_ubyteN,
37         [{ return PostLegalizerHelper.matchCvtF32UByteN(*${cvt_f32_ubyteN}, ${matchinfo}); }]),
38  (apply [{ PostLegalizerHelper.applyCvtF32UByteN(*${cvt_f32_ubyteN}, ${matchinfo}); }])>;
39
40def clamp_i64_to_i16_matchdata : GIDefMatchData<"AMDGPUPreLegalizerCombinerHelper::ClampI64ToI16MatchInfo">;
41
42def clamp_i64_to_i16 : GICombineRule<
43  (defs root:$clamp_i64_to_i16, clamp_i64_to_i16_matchdata:$matchinfo),
44  (match (wip_match_opcode G_TRUNC):$clamp_i64_to_i16,
45      [{ return PreLegalizerHelper.matchClampI64ToI16(*${clamp_i64_to_i16}, MRI, *MF, ${matchinfo}); }]),
46  (apply [{ PreLegalizerHelper.applyClampI64ToI16(*${clamp_i64_to_i16}, ${matchinfo}); }])>;
47
48// Combines which should only apply on SI/VI
49def gfx6gfx7_combines : GICombineGroup<[fcmp_select_to_fmin_fmax_legacy]>;
50
51def AMDGPUPreLegalizerCombinerHelper: GICombinerHelper<
52  "AMDGPUGenPreLegalizerCombinerHelper", [all_combines, clamp_i64_to_i16]> {
53  let DisableRuleOption = "amdgpuprelegalizercombiner-disable-rule";
54  let StateClass = "AMDGPUPreLegalizerCombinerHelperState";
55}
56
57def AMDGPUPostLegalizerCombinerHelper: GICombinerHelper<
58  "AMDGPUGenPostLegalizerCombinerHelper",
59  [all_combines, gfx6gfx7_combines,
60   uchar_to_float, cvt_f32_ubyteN]> {
61  let DisableRuleOption = "amdgpupostlegalizercombiner-disable-rule";
62  let StateClass = "AMDGPUPostLegalizerCombinerHelperState";
63  let AdditionalArguments = [];
64}
65
66def AMDGPURegBankCombinerHelper : GICombinerHelper<
67  "AMDGPUGenRegBankCombinerHelper", []> {
68  let DisableRuleOption = "amdgpuregbankcombiner-disable-rule";
69}
70