Skip to content

Commit d7d88b9

Browse files
committed
GlobalISel: Fix assertion on wide G_ZEXT sources
It's possible to have a type that needs a mask greater than 64-bits.
1 parent a70b993 commit d7d88b9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class LegalizationArtifactCombiner {
113113
LLVM_DEBUG(dbgs() << ".. Combine MI: " << MI;);
114114
LLT SrcTy = MRI.getType(SrcReg);
115115
APInt Mask = APInt::getAllOnesValue(SrcTy.getScalarSizeInBits());
116-
auto MIBMask = Builder.buildConstant(DstTy, Mask.getZExtValue());
116+
auto MIBMask = Builder.buildConstant(
117+
DstTy, Mask.zext(DstTy.getScalarSizeInBits()));
117118
Builder.buildAnd(DstReg, Builder.buildAnyExtOrTrunc(DstTy, TruncSrc),
118119
MIBMask);
119120
markInstAndDefDead(MI, *MRI.getVRegDef(SrcReg), DeadInsts);

llvm/test/CodeGen/AMDGPU/GlobalISel/artifact-combiner-zext.mir

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,28 @@ body: |
8888
%2:_(<3 x s32>) = G_ZEXT %1
8989
$vgpr0_vgpr1_vgpr2 = COPY %2
9090
...
91+
92+
# Test for "Too many bits for uint64_t" assertion when combining
93+
# zexts with wide sources.
94+
---
95+
name: test_zext_128_trunc_s128_merge
96+
body: |
97+
bb.0:
98+
liveins: $vgpr0_vgpr1
99+
100+
; CHECK-LABEL: name: test_zext_128_trunc_s128_merge
101+
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
102+
; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
103+
; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 -1
104+
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4294967295
105+
; CHECK: [[AND:%[0-9]+]]:_(s64) = G_AND [[COPY]], [[C]]
106+
; CHECK: [[AND1:%[0-9]+]]:_(s64) = G_AND [[COPY1]], [[C1]]
107+
; CHECK: [[MV:%[0-9]+]]:_(s128) = G_MERGE_VALUES [[AND]](s64), [[AND1]](s64)
108+
; CHECK: $vgpr0_vgpr1_vgpr2_vgpr3 = COPY [[MV]](s128)
109+
%0:_(s64) = COPY $vgpr0_vgpr1
110+
%1:_(s64) = COPY $vgpr0_vgpr1
111+
%2:_(s128) = G_MERGE_VALUES %0, %1
112+
%3:_(s96) = G_TRUNC %2
113+
%4:_(s128) = G_ZEXT %3
114+
$vgpr0_vgpr1_vgpr2_vgpr3 = COPY %4
115+
...

0 commit comments

Comments
 (0)