Skip to content

Commit 7bf13fe

Browse files
authored
[DAG] Fold (sext (sext_inreg x)) -> (sext (trunc x)) if the trunc is free (#77616)
1 parent e034f20 commit 7bf13fe

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13381,9 +13381,9 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
1338113381
if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG) {
1338213382
SDValue N00 = N0.getOperand(0);
1338313383
EVT ExtVT = cast<VTSDNode>(N0->getOperand(1))->getVT();
13384-
if (N00.getOpcode() == ISD::TRUNCATE &&
13384+
if ((N00.getOpcode() == ISD::TRUNCATE || TLI.isTruncateFree(N00, ExtVT)) &&
1338513385
(!LegalTypes || TLI.isTypeLegal(ExtVT))) {
13386-
SDValue T = DAG.getNode(ISD::TRUNCATE, DL, ExtVT, N00.getOperand(0));
13386+
SDValue T = DAG.getNode(ISD::TRUNCATE, DL, ExtVT, N00);
1338713387
return DAG.getNode(ISD::SIGN_EXTEND, DL, VT, T);
1338813388
}
1338913389
}

llvm/test/CodeGen/X86/abds.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ define i16 @abd_ext_i16_i32(i16 %a, i32 %b) nounwind {
141141
;
142142
; X64-LABEL: abd_ext_i16_i32:
143143
; X64: # %bb.0:
144+
; X64-NEXT: # kill: def $edi killed $edi def $rdi
145+
; X64-NEXT: movswq %di, %rcx
144146
; X64-NEXT: movslq %esi, %rax
145-
; X64-NEXT: movswl %di, %ecx
146-
; X64-NEXT: movslq %ecx, %rcx
147147
; X64-NEXT: subq %rax, %rcx
148148
; X64-NEXT: movq %rcx, %rax
149149
; X64-NEXT: negq %rax
@@ -232,9 +232,9 @@ define i32 @abd_ext_i32_i16(i32 %a, i16 %b) nounwind {
232232
;
233233
; X64-LABEL: abd_ext_i32_i16:
234234
; X64: # %bb.0:
235+
; X64-NEXT: # kill: def $esi killed $esi def $rsi
236+
; X64-NEXT: movswq %si, %rax
235237
; X64-NEXT: movslq %edi, %rcx
236-
; X64-NEXT: movswl %si, %eax
237-
; X64-NEXT: cltq
238238
; X64-NEXT: subq %rax, %rcx
239239
; X64-NEXT: movq %rcx, %rax
240240
; X64-NEXT: negq %rax

llvm/test/CodeGen/X86/pr14088.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ define i32 @f(i1 %foo, ptr %tm_year2, ptr %bar, i16 %zed, i32 %zed2) {
2626
; CHECK-NEXT: imull $100, %ecx, %ecx
2727
; CHECK-NEXT: subl %ecx, %eax
2828
; CHECK-NEXT: movw %ax, (%rsi)
29-
; CHECK-NEXT: cwtl
30-
; CHECK-NEXT: cltq
29+
; CHECK-NEXT: movswq %ax, %rax
3130
; CHECK-NEXT: imulq $1717986919, %rax, %rax # imm = 0x66666667
3231
; CHECK-NEXT: movq %rax, %rcx
3332
; CHECK-NEXT: shrq $63, %rcx

0 commit comments

Comments
 (0)