Skip to content

Commit 88b1d16

Browse files
committed
[Mips] Use getSignedConstant() in or combine
Fixes #125954.
1 parent e225677 commit 88b1d16

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

llvm/lib/Target/Mips/MipsISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ static SDValue performORCombine(SDNode *N, SelectionDAG &DAG,
10041004
return DAG.getNode(
10051005
MipsISD::Ins, DL, N->getValueType(0),
10061006
isConstCase
1007-
? DAG.getConstant(CN1->getSExtValue() >> SMPos0, DL, ValTy)
1007+
? DAG.getSignedConstant(CN1->getSExtValue() >> SMPos0, DL, ValTy)
10081008
: SrlX,
10091009
DAG.getConstant(SMPos0, DL, MVT::i32),
10101010
DAG.getConstant(ValTy.getSizeInBits() / 8 < 8 ? SMSize0 & 31

llvm/test/CodeGen/Mips/dins.ll

+53
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,56 @@ entry:
304304
store volatile i32 %or, ptr %x.addr, align 4
305305
ret i32 %and
306306
}
307+
308+
define i32 @pr125954(i32 %arg, i1 %c) {
309+
; MIPS64R2-LABEL: pr125954:
310+
; MIPS64R2: # %bb.0:
311+
; MIPS64R2-NEXT: sll $1, $4, 0
312+
; MIPS64R2-NEXT: addiu $2, $zero, -1
313+
; MIPS64R2-NEXT: move $3, $1
314+
; MIPS64R2-NEXT: ins $3, $2, 8, 24
315+
; MIPS64R2-NEXT: andi $2, $1, 255
316+
; MIPS64R2-NEXT: sll $1, $5, 0
317+
; MIPS64R2-NEXT: andi $1, $1, 1
318+
; MIPS64R2-NEXT: jr $ra
319+
; MIPS64R2-NEXT: movn $2, $3, $1
320+
;
321+
; MIPS32R2-LABEL: pr125954:
322+
; MIPS32R2: # %bb.0:
323+
; MIPS32R2-NEXT: andi $2, $4, 255
324+
; MIPS32R2-NEXT: addiu $1, $zero, -256
325+
; MIPS32R2-NEXT: or $1, $2, $1
326+
; MIPS32R2-NEXT: andi $3, $5, 1
327+
; MIPS32R2-NEXT: jr $ra
328+
; MIPS32R2-NEXT: movn $2, $1, $3
329+
;
330+
; MIPS16-LABEL: pr125954:
331+
; MIPS16: # %bb.0:
332+
; MIPS16-NEXT: li $6, 1
333+
; MIPS16-NEXT: and $6, $5
334+
; MIPS16-NEXT: li $2, 255
335+
; MIPS16-NEXT: and $2, $4
336+
; MIPS16-NEXT: move $3, $zero
337+
; MIPS16-NEXT: beqz $6, $BB2_2 # 16 bit inst
338+
; MIPS16-NEXT: # %bb.1:
339+
; MIPS16-NEXT: addiu $3, -256
340+
; MIPS16-NEXT: or $2, $3
341+
; MIPS16-NEXT: $BB2_2:
342+
; MIPS16-NEXT: jrc $ra
343+
;
344+
; MIPS64R2N32-LABEL: pr125954:
345+
; MIPS64R2N32: # %bb.0:
346+
; MIPS64R2N32-NEXT: sll $1, $4, 0
347+
; MIPS64R2N32-NEXT: addiu $2, $zero, -1
348+
; MIPS64R2N32-NEXT: move $3, $1
349+
; MIPS64R2N32-NEXT: ins $3, $2, 8, 24
350+
; MIPS64R2N32-NEXT: andi $2, $1, 255
351+
; MIPS64R2N32-NEXT: sll $1, $5, 0
352+
; MIPS64R2N32-NEXT: andi $1, $1, 1
353+
; MIPS64R2N32-NEXT: jr $ra
354+
; MIPS64R2N32-NEXT: movn $2, $3, $1
355+
%and = and i32 %arg, 255
356+
%or = or i32 %and, -256
357+
%sel = select i1 %c, i32 %or, i32 %and
358+
ret i32 %sel
359+
}

0 commit comments

Comments
 (0)