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<"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 matchFMinFMaxLegacy(*${select}, MRI, *MF, ${matchinfo}); }]), 20 (apply [{ 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 matchUCharToFloat(*${itofp}, MRI, *MF, Helper); }]), 27 (apply [{ applyUCharToFloat(*${itofp}); }])>; 28 29def cvt_f32_ubyteN_matchdata : GIDefMatchData<"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 matchCvtF32UByteN(*${cvt_f32_ubyteN}, MRI, *MF, ${matchinfo}); }]), 38 (apply [{ applyCvtF32UByteN(*${cvt_f32_ubyteN}, ${matchinfo}); }])>; 39 40// Combines which should only apply on SI/VI 41def gfx6gfx7_combines : GICombineGroup<[fcmp_select_to_fmin_fmax_legacy]>; 42 43 44def AMDGPUPreLegalizerCombinerHelper: GICombinerHelper< 45 "AMDGPUGenPreLegalizerCombinerHelper", [all_combines, 46 elide_br_by_inverting_cond]> { 47 let DisableRuleOption = "amdgpuprelegalizercombiner-disable-rule"; 48} 49 50 51// FIXME: combines_for_extload can introduce illegal extloads which 52// aren't re-legalized. 53// FIXME: Is there a way to remove a single item from all_combines? 54def all_combines_minus_extload : GICombineGroup<[trivial_combines, 55 ptr_add_immed_chain, combine_indexed_load_store, undef_combines, 56 identity_combines] 57>; 58 59def AMDGPUPostLegalizerCombinerHelper: GICombinerHelper< 60 "AMDGPUGenPostLegalizerCombinerHelper", 61 [all_combines_minus_extload, gfx6gfx7_combines, 62 uchar_to_float, cvt_f32_ubyteN]> { 63 let DisableRuleOption = "amdgpupostlegalizercombiner-disable-rule"; 64} 65 66def AMDGPURegBankCombinerHelper : GICombinerHelper< 67 "AMDGPUGenRegBankCombinerHelper", []> { 68 let DisableRuleOption = "amdgpuregbankcombiner-disable-rule"; 69} 70