Skip to content

Commit f04284c

Browse files
committed
[TargetLowering] SimplifyDemandedBits ISD::SRA multi-use handling
Call SimplifyMultipleUseDemandedBits to peek through extended source args with multiple uses
1 parent 81f385b commit f04284c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,16 @@ bool TargetLowering::SimplifyDemandedBits(
15341534
if (Known.One[BitWidth - ShAmt - 1])
15351535
// New bits are known one.
15361536
Known.One.setHighBits(ShAmt);
1537+
1538+
// Attempt to avoid multi-use ops if we don't need anything from them.
1539+
if (!InDemandedMask.isAllOnesValue() || !DemandedElts.isAllOnesValue()) {
1540+
SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
1541+
Op0, InDemandedMask, DemandedElts, TLO.DAG, Depth + 1);
1542+
if (DemandedOp0) {
1543+
SDValue NewOp = TLO.DAG.getNode(ISD::SRA, dl, VT, DemandedOp0, Op1);
1544+
return TLO.CombineTo(Op, NewOp);
1545+
}
1546+
}
15371547
}
15381548
break;
15391549
}

llvm/test/CodeGen/X86/const-shift-of-constmasked.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,9 +1870,9 @@ define i64 @test_i64_18446744065119617024_mask_ashr_1(i64 %a0) {
18701870
define i64 @test_i64_18446744065119617024_mask_ashr_32(i64 %a0) {
18711871
; X32-LABEL: test_i64_18446744065119617024_mask_ashr_32:
18721872
; X32: # %bb.0:
1873-
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
1873+
; X32-NEXT: movl {{[0-9]+}}(%esp), %edx
1874+
; X32-NEXT: movl %edx, %eax
18741875
; X32-NEXT: andl $-2, %eax
1875-
; X32-NEXT: movl %eax, %edx
18761876
; X32-NEXT: sarl $31, %edx
18771877
; X32-NEXT: retl
18781878
;

0 commit comments

Comments
 (0)