Skip to content

Commit 35d771f

Browse files
committed
[RISCV][GISel] Fix failure to legalize non-power of 2 shifts between i32 and i64 on RV64.
We weren't legalizing the shift amount to i64.
1 parent f9306f6 commit 35d771f

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) {
5050
.legalFor({{s32, s32}, {XLenLLT, XLenLLT}})
5151
.widenScalarToNextPow2(0)
5252
.clampScalar(1, s32, XLenLLT)
53-
.clampScalar(0, s32, XLenLLT);
53+
.clampScalar(0, s32, XLenLLT)
54+
.minScalarSameAs(1, 0);
5455

5556
if (ST.is64Bit()) {
5657
getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})

llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-ashr.mir

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,32 @@ body: |
359359
PseudoRET implicit $x10, implicit $x11, implicit $x12
360360
361361
...
362+
---
363+
name: ashr_i48
364+
body: |
365+
bb.0:
366+
liveins: $x10, $x11
367+
368+
; CHECK-LABEL: name: ashr_i48
369+
; CHECK: liveins: $x10, $x11
370+
; CHECK-NEXT: {{ $}}
371+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
372+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
373+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
374+
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s64) = G_SHL [[COPY]], [[C]](s64)
375+
; CHECK-NEXT: [[ASHR:%[0-9]+]]:_(s64) = G_ASHR [[SHL]], [[C]](s64)
376+
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 281474976710655
377+
; CHECK-NEXT: [[AND:%[0-9]+]]:_(s64) = G_AND [[COPY1]], [[C1]]
378+
; CHECK-NEXT: [[ASHR1:%[0-9]+]]:_(s64) = G_ASHR [[ASHR]], [[AND]](s64)
379+
; CHECK-NEXT: $x10 = COPY [[ASHR1]](s64)
380+
; CHECK-NEXT: PseudoRET implicit $x10
381+
%2:_(s64) = COPY $x10
382+
%0:_(s48) = G_TRUNC %2(s64)
383+
%3:_(s64) = COPY $x11
384+
%1:_(s48) = G_TRUNC %3(s64)
385+
%4:_(s48) = G_ASHR %0, %1(s48)
386+
%5:_(s64) = G_ANYEXT %4(s48)
387+
$x10 = COPY %5(s64)
388+
PseudoRET implicit $x10
389+
390+
...

llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-lshr.mir

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,31 @@ body: |
352352
PseudoRET implicit $x10, implicit $x11, implicit $x12
353353
354354
...
355+
---
356+
name: lshr_i48
357+
body: |
358+
bb.0:
359+
liveins: $x10, $x11
360+
361+
; CHECK-LABEL: name: lshr_i48
362+
; CHECK: liveins: $x10, $x11
363+
; CHECK-NEXT: {{ $}}
364+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
365+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
366+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 281474976710655
367+
; CHECK-NEXT: [[AND:%[0-9]+]]:_(s64) = G_AND [[COPY]], [[C]]
368+
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 281474976710655
369+
; CHECK-NEXT: [[AND1:%[0-9]+]]:_(s64) = G_AND [[COPY1]], [[C1]]
370+
; CHECK-NEXT: [[LSHR:%[0-9]+]]:_(s64) = G_LSHR [[AND]], [[AND1]](s64)
371+
; CHECK-NEXT: $x10 = COPY [[LSHR]](s64)
372+
; CHECK-NEXT: PseudoRET implicit $x10
373+
%2:_(s64) = COPY $x10
374+
%0:_(s48) = G_TRUNC %2(s64)
375+
%3:_(s64) = COPY $x11
376+
%1:_(s48) = G_TRUNC %3(s64)
377+
%4:_(s48) = G_LSHR %0, %1(s48)
378+
%5:_(s64) = G_ANYEXT %4(s48)
379+
$x10 = COPY %5(s64)
380+
PseudoRET implicit $x10
381+
382+
...

llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-shl.mir

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,29 @@ body: |
310310
PseudoRET implicit $x10, implicit $x11, implicit $x12
311311
312312
...
313+
---
314+
name: shl_i48
315+
body: |
316+
bb.0:
317+
liveins: $x10, $x11
318+
319+
; CHECK-LABEL: name: shl_i48
320+
; CHECK: liveins: $x10, $x11
321+
; CHECK-NEXT: {{ $}}
322+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
323+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
324+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 281474976710655
325+
; CHECK-NEXT: [[AND:%[0-9]+]]:_(s64) = G_AND [[COPY1]], [[C]]
326+
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s64) = G_SHL [[COPY]], [[AND]](s64)
327+
; CHECK-NEXT: $x10 = COPY [[SHL]](s64)
328+
; CHECK-NEXT: PseudoRET implicit $x10
329+
%2:_(s64) = COPY $x10
330+
%0:_(s48) = G_TRUNC %2(s64)
331+
%3:_(s64) = COPY $x11
332+
%1:_(s48) = G_TRUNC %3(s64)
333+
%4:_(s48) = G_SHL %0, %1(s48)
334+
%5:_(s64) = G_ANYEXT %4(s48)
335+
$x10 = COPY %5(s64)
336+
PseudoRET implicit $x10
337+
338+
...

0 commit comments

Comments
 (0)