Skip to content

Commit c9c5d82

Browse files
committed
hooking up dagcombine and legalize
1 parent 7fb2ce4 commit c9c5d82

16 files changed

+142
-114
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
15311531
if (Opcode == Instruction::Store)
15321532
LA = getTLI()->getTruncStoreAction(LT.second, MemVT);
15331533
else
1534-
LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT);
1534+
LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT,
1535+
AddressSpace);
15351536

15361537
if (LA != TargetLowering::Legal && LA != TargetLowering::Custom) {
15371538
// This is a vector load/store for some illegal type that is scalarized.

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,9 +1487,16 @@ class LLVM_ABI TargetLoweringBase {
14871487
assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValI < MVT::VALUETYPE_SIZE &&
14881488
MemI < MVT::VALUETYPE_SIZE && "Table isn't big enough!");
14891489
unsigned Shift = 4 * ExtType;
1490-
return (
1491-
LegalizeAction)((LoadExtActions.at(AddrSpace)[ValI][MemI] >> Shift) &
1492-
0xf);
1490+
if (LoadExtActions.count(AddrSpace)) {
1491+
return (
1492+
LegalizeAction)((LoadExtActions.at(AddrSpace)[ValI][MemI] >> Shift) &
1493+
0xf);
1494+
} else {
1495+
assert(AddrSpace != 0 && "addrspace zero should be initialized");
1496+
return (
1497+
LegalizeAction)((LoadExtActions.at(0)[ValI][MemI] >> Shift) &
1498+
0xf);
1499+
}
14931500
}
14941501

14951502
/// Return true if the specified load with extension is legal on this target.
@@ -2649,6 +2656,7 @@ class LLVM_ABI TargetLoweringBase {
26492656
assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() &&
26502657
MemVT.isValid() && "Table isn't big enough!");
26512658
assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2659+
assert(AddrSpace == 0 && "expected addrspace 0");
26522660
unsigned Shift = 4 * ExtType;
26532661
LoadExtActions[AddrSpace][ValVT.SimpleTy][MemVT.SimpleTy] &=
26542662
~((uint16_t)0xF << Shift);
@@ -3140,7 +3148,7 @@ class LLVM_ABI TargetLoweringBase {
31403148
LType = ISD::SEXTLOAD;
31413149
}
31423150

3143-
return isLoadExtLegal(LType, VT, LoadVT);
3151+
return isLoadExtLegal(LType, VT, LoadVT, Load->getPointerAddressSpace());
31443152
}
31453153

31463154
/// Return true if any actual instruction that defines a value of type FromTy
@@ -3757,9 +3765,9 @@ class LLVM_ABI TargetLoweringBase {
37573765
/// specific value type and extension type. Uses 4-bits to store the action
37583766
/// for each of the 4 load ext types. These actions can be specified for each
37593767
/// address space.
3760-
using LoadExtActionMap =
3761-
std::map<unsigned, std::array<std::array<uint16_t, MVT::VALUETYPE_SIZE>,
3762-
MVT::VALUETYPE_SIZE>>;
3768+
using LoadExtActionMapTy =
3769+
std::array<std::array<uint16_t, MVT::VALUETYPE_SIZE>, MVT::VALUETYPE_SIZE>;
3770+
using LoadExtActionMap = std::map<unsigned, LoadExtActionMapTy>;
37633771
LoadExtActionMap LoadExtActions;
37643772

37653773
/// Similar to LoadExtActions, but for atomic loads. Only Legal or Expand

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7328,7 +7328,8 @@ bool CodeGenPrepare::optimizeLoadExt(LoadInst *Load) {
73287328

73297329
// Reject cases that won't be matched as extloads.
73307330
if (!LoadResultVT.bitsGT(TruncVT) || !TruncVT.isRound() ||
7331-
!TLI->isLoadExtLegal(ISD::ZEXTLOAD, LoadResultVT, TruncVT))
7331+
!TLI->isLoadExtLegal(ISD::ZEXTLOAD, LoadResultVT, TruncVT,
7332+
Load->getPointerAddressSpace()))
73327333
return false;
73337334

73347335
IRBuilder<> Builder(Load->getNextNode());

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 66 additions & 37 deletions
Large diffs are not rendered by default.

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ void SelectionDAGLegalize::LegalizeLoadOps(SDNode *Node) {
742742
// nice to have an effective generic way of getting these benefits...
743743
// Until such a way is found, don't insist on promoting i1 here.
744744
(SrcVT != MVT::i1 ||
745-
TLI.getLoadExtAction(ExtType, Node->getValueType(0), MVT::i1) ==
746-
TargetLowering::Promote)) {
745+
TLI.getLoadExtAction(ExtType, Node->getValueType(0), MVT::i1,
746+
LD->getAddressSpace()) == TargetLowering::Promote)) {
747747
// Promote to a byte-sized load if not loading an integral number of
748748
// bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24.
749749
unsigned NewWidth = SrcVT.getStoreSizeInBits();
@@ -856,7 +856,7 @@ void SelectionDAGLegalize::LegalizeLoadOps(SDNode *Node) {
856856
} else {
857857
bool isCustom = false;
858858
switch (TLI.getLoadExtAction(ExtType, Node->getValueType(0),
859-
SrcVT.getSimpleVT())) {
859+
SrcVT.getSimpleVT(), LD->getAddressSpace())) {
860860
default: llvm_unreachable("This action is not supported yet!");
861861
case TargetLowering::Custom:
862862
isCustom = true;
@@ -884,13 +884,15 @@ void SelectionDAGLegalize::LegalizeLoadOps(SDNode *Node) {
884884

885885
case TargetLowering::Expand: {
886886
EVT DestVT = Node->getValueType(0);
887-
if (!TLI.isLoadExtLegal(ISD::EXTLOAD, DestVT, SrcVT)) {
887+
if (!TLI.isLoadExtLegal(ISD::EXTLOAD, DestVT, SrcVT,
888+
LD->getAddressSpace())) {
888889
// If the source type is not legal, see if there is a legal extload to
889890
// an intermediate type that we can then extend further.
890891
EVT LoadVT = TLI.getRegisterType(SrcVT.getSimpleVT());
891892
if ((LoadVT.isFloatingPoint() == SrcVT.isFloatingPoint()) &&
892893
(TLI.isTypeLegal(SrcVT) || // Same as SrcVT == LoadVT?
893-
TLI.isLoadExtLegal(ExtType, LoadVT, SrcVT))) {
894+
TLI.isLoadExtLegal(ExtType, LoadVT, SrcVT,
895+
LD->getAddressSpace()))) {
894896
// If we are loading a legal type, this is a non-extload followed by a
895897
// full extend.
896898
ISD::LoadExtType MidExtType =

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
301301
ISD::LoadExtType ExtType = LD->getExtensionType();
302302
EVT LoadedVT = LD->getMemoryVT();
303303
if (LoadedVT.isVector() && ExtType != ISD::NON_EXTLOAD)
304-
Action = TLI.getLoadExtAction(ExtType, LD->getValueType(0), LoadedVT);
304+
Action = TLI.getLoadExtAction(ExtType, LD->getValueType(0), LoadedVT,
305+
LD->getAddressSpace());
305306
break;
306307
}
307308
case ISD::STORE: {

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12364,7 +12364,8 @@ SDValue TargetLowering::scalarizeExtractedVectorLoad(EVT ResultVT,
1236412364
if (ResultVT.bitsGT(VecEltVT)) {
1236512365
// If the result type of vextract is wider than the load, then issue an
1236612366
// extending load instead.
12367-
ISD::LoadExtType ExtType = isLoadExtLegal(ISD::ZEXTLOAD, ResultVT, VecEltVT)
12367+
ISD::LoadExtType ExtType = isLoadExtLegal(ISD::ZEXTLOAD, ResultVT, VecEltVT,
12368+
OriginalLoad->getAddressSpace())
1236812369
? ISD::ZEXTLOAD
1236912370
: ISD::EXTLOAD;
1237012371
Load = DAG.getExtLoad(ExtType, DL, ResultVT, OriginalLoad->getChain(),

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ void TargetLoweringBase::initActions() {
731731
memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
732732
memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
733733
memset(CondCodeActions, 0, sizeof(CondCodeActions));
734+
LoadExtActions[0].fill({});
735+
734736
llvm::fill(RegClassForVT, nullptr);
735737
llvm::fill(TargetDAGCombineArray, 0);
736738

llvm/test/CodeGen/AMDGPU/call-argument-types.ll

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ define amdgpu_kernel void @test_call_external_void_func_i1_zeroext(i32) #0 {
279279
; VI-NEXT: s_addc_u32 s5, s5, external_void_func_i1_zeroext@rel32@hi+12
280280
; VI-NEXT: s_mov_b64 s[2:3], s[38:39]
281281
; VI-NEXT: s_mov_b32 s32, 0
282-
; VI-NEXT: v_and_b32_e32 v0, 1, v0
283282
; VI-NEXT: s_swappc_b64 s[30:31], s[4:5]
284283
; VI-NEXT: s_endpgm
285284
;
@@ -302,7 +301,6 @@ define amdgpu_kernel void @test_call_external_void_func_i1_zeroext(i32) #0 {
302301
; CI-NEXT: s_addc_u32 s5, s5, external_void_func_i1_zeroext@rel32@hi+12
303302
; CI-NEXT: s_mov_b64 s[2:3], s[38:39]
304303
; CI-NEXT: s_mov_b32 s32, 0
305-
; CI-NEXT: v_and_b32_e32 v0, 1, v0
306304
; CI-NEXT: s_swappc_b64 s[30:31], s[4:5]
307305
; CI-NEXT: s_endpgm
308306
;
@@ -325,7 +323,6 @@ define amdgpu_kernel void @test_call_external_void_func_i1_zeroext(i32) #0 {
325323
; GFX9-NEXT: s_addc_u32 s5, s5, external_void_func_i1_zeroext@rel32@hi+12
326324
; GFX9-NEXT: s_mov_b64 s[2:3], s[38:39]
327325
; GFX9-NEXT: s_mov_b32 s32, 0
328-
; GFX9-NEXT: v_and_b32_e32 v0, 1, v0
329326
; GFX9-NEXT: s_swappc_b64 s[30:31], s[4:5]
330327
; GFX9-NEXT: s_endpgm
331328
;
@@ -340,7 +337,6 @@ define amdgpu_kernel void @test_call_external_void_func_i1_zeroext(i32) #0 {
340337
; GFX11-NEXT: s_add_u32 s2, s2, external_void_func_i1_zeroext@rel32@lo+4
341338
; GFX11-NEXT: s_addc_u32 s3, s3, external_void_func_i1_zeroext@rel32@hi+12
342339
; GFX11-NEXT: s_mov_b32 s32, 0
343-
; GFX11-NEXT: v_and_b32_e32 v0, 1, v0
344340
; GFX11-NEXT: s_swappc_b64 s[30:31], s[2:3]
345341
; GFX11-NEXT: s_endpgm
346342
;
@@ -360,7 +356,6 @@ define amdgpu_kernel void @test_call_external_void_func_i1_zeroext(i32) #0 {
360356
; HSA-NEXT: s_addc_u32 s9, s9, external_void_func_i1_zeroext@rel32@hi+12
361357
; HSA-NEXT: s_mov_b64 s[6:7], s[4:5]
362358
; HSA-NEXT: s_mov_b32 s32, 0
363-
; HSA-NEXT: v_and_b32_e32 v0, 1, v0
364359
; HSA-NEXT: s_swappc_b64 s[30:31], s[8:9]
365360
; HSA-NEXT: s_endpgm
366361
%var = load volatile i1, ptr addrspace(1) poison

llvm/test/CodeGen/AMDGPU/function-returns.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ define zeroext i1 @i1_zeroext_func_void() #0 {
3636
; GFX789-NEXT: s_mov_b32 s6, -1
3737
; GFX789-NEXT: buffer_load_ubyte v0, off, s[4:7], 0
3838
; GFX789-NEXT: s_waitcnt vmcnt(0)
39+
; GFX789-NEXT: v_and_b32_e32 v0, 1, v0
3940
; GFX789-NEXT: s_setpc_b64 s[30:31]
4041
;
4142
; GFX11-LABEL: i1_zeroext_func_void:
@@ -45,6 +46,7 @@ define zeroext i1 @i1_zeroext_func_void() #0 {
4546
; GFX11-NEXT: s_mov_b32 s2, -1
4647
; GFX11-NEXT: buffer_load_u8 v0, off, s[0:3], 0
4748
; GFX11-NEXT: s_waitcnt vmcnt(0)
49+
; GFX11-NEXT: v_and_b32_e32 v0, 1, v0
4850
; GFX11-NEXT: s_setpc_b64 s[30:31]
4951
%val = load i1, ptr addrspace(1) poison
5052
ret i1 %val

0 commit comments

Comments
 (0)