Skip to content

Commit 848ba38

Browse files
authored
[DAG] fold AVGFLOORS to AVGFLOORU for non-negative operand (#84746) (#129678)
Fold ISD::AVGFLOORS to ISD::AVGFLOORU for non-negative operand. Cover test is modified for uhadd with zero extension. Fixes #84746
1 parent a5c33e6 commit 848ba38

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5390,6 +5390,12 @@ SDValue DAGCombiner::visitAVG(SDNode *N) {
53905390
}
53915391
}
53925392

5393+
// Fold avgfloors(x,y) -> avgflooru(x,y) if both x and y are non-negative
5394+
if (Opcode == ISD::AVGFLOORS && hasOperation(ISD::AVGFLOORU, VT)) {
5395+
if (DAG.SignBitIsZero(N0) && DAG.SignBitIsZero(N1))
5396+
return DAG.getNode(ISD::AVGFLOORU, DL, VT, N0, N1);
5397+
}
5398+
53935399
return SDValue();
53945400
}
53955401

llvm/test/CodeGen/AArch64/aarch64-known-bits-hadd.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ define <8 x i16> @rhaddu_zext(<8 x i8> %a0, <8 x i8> %a1) {
3535
define <8 x i16> @hadds_zext(<8 x i8> %a0, <8 x i8> %a1) {
3636
; CHECK-LABEL: hadds_zext:
3737
; CHECK: // %bb.0:
38-
; CHECK-NEXT: ushll v0.8h, v0.8b, #0
39-
; CHECK-NEXT: ushll v1.8h, v1.8b, #0
40-
; CHECK-NEXT: shadd v0.8h, v0.8h, v1.8h
38+
; CHECK-NEXT: uhadd v0.8b, v0.8b, v1.8b
39+
; CHECK-NEXT: ushll v0.8h, v0.8b, #0
4140
; CHECK-NEXT: ret
4241
%x0 = zext <8 x i8> %a0 to <8 x i16>
4342
%x1 = zext <8 x i8> %a1 to <8 x i16>

0 commit comments

Comments
 (0)