Skip to content

Commit 2f89d4d

Browse files
authored
Merge branch 'main' into minnum_ieee_ppc
2 parents 581a313 + ddb8870 commit 2f89d4d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,9 @@ bool RISCVDAGToDAGISel::trySignedBitfieldExtract(SDNode *Node) {
653653
return false;
654654

655655
const unsigned Msb = ExtSize - 1;
656-
const unsigned Lsb = RightShAmt;
656+
// If the shift-right amount is greater than Msb, it means that extracts
657+
// the X[Msb] bit and sign-extend it.
658+
const unsigned Lsb = RightShAmt > Msb ? Msb : RightShAmt;
657659

658660
SDNode *TH_EXT = BitfieldExtract(N0, Msb, Lsb, DL, VT);
659661
ReplaceNode(Node, TH_EXT);

llvm/test/CodeGen/RISCV/rv32xtheadbb.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,38 @@ define i64 @no_sexth_i64(i64 %a) nounwind {
401401
ret i64 %shr
402402
}
403403

404+
define i32 @sext_sextinreg_sra(i16 %a) nounwind {
405+
; RV32I-LABEL: sext_sextinreg_sra:
406+
; RV32I: # %bb.0:
407+
; RV32I-NEXT: slli a0, a0, 16
408+
; RV32I-NEXT: srai a0, a0, 26
409+
; RV32I-NEXT: ret
410+
;
411+
; RV32XTHEADBB-LABEL: sext_sextinreg_sra:
412+
; RV32XTHEADBB: # %bb.0:
413+
; RV32XTHEADBB-NEXT: th.ext a0, a0, 15, 10
414+
; RV32XTHEADBB-NEXT: ret
415+
%sext = sext i16 %a to i32
416+
%shr = ashr exact i32 %sext, 10
417+
ret i32 %shr
418+
}
419+
420+
define i32 @sext_sextinreg_sra_2(i16 %a) nounwind {
421+
; RV32I-LABEL: sext_sextinreg_sra_2:
422+
; RV32I: # %bb.0:
423+
; RV32I-NEXT: slli a0, a0, 16
424+
; RV32I-NEXT: srai a0, a0, 31
425+
; RV32I-NEXT: ret
426+
;
427+
; RV32XTHEADBB-LABEL: sext_sextinreg_sra_2:
428+
; RV32XTHEADBB: # %bb.0:
429+
; RV32XTHEADBB-NEXT: th.ext a0, a0, 15, 15
430+
; RV32XTHEADBB-NEXT: ret
431+
%sext = sext i16 %a to i32
432+
%shr = ashr exact i32 %sext, 24
433+
ret i32 %shr
434+
}
435+
404436
define i32 @zexth_i32(i32 %a) nounwind {
405437
; RV32I-LABEL: zexth_i32:
406438
; RV32I: # %bb.0:

llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ define i64 @sel_shift_bool_i64(i1 %t) {
263263
ret i64 %shl
264264
}
265265

266-
; FIXME: This should use sraiw+and
267266
define i64 @sraiw_andi(i32 signext %0, i32 signext %1) nounwind {
268267
; RV32-LABEL: sraiw_andi:
269268
; RV32: # %bb.0: # %entry

0 commit comments

Comments
 (0)