Skip to content

Commit de54c05

Browse files
committed
[SystemZ] Fold AHIMux in foldMemoryOperandImpl.
AHIMux can be folded the same way as AHI. Review: Ulrich Weigand llvm-svn: 332703
1 parent 981a34c commit de54c05

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,13 @@ void SystemZDAGToDAGISel::Select(SDNode *Node) {
15091509
CCMask = CurDAG->getConstant(ConstCCValid ^ ConstCCMask, SDLoc(Node),
15101510
CCMask.getValueType());
15111511
SDValue Op4 = Node->getOperand(4);
1512-
Node = CurDAG->UpdateNodeOperands(Node, Op1, Op0, CCValid, CCMask, Op4);
1512+
SDNode *UpdatedNode =
1513+
CurDAG->UpdateNodeOperands(Node, Op1, Op0, CCValid, CCMask, Op4);
1514+
if (UpdatedNode != Node) {
1515+
// In case this node already exists, replace Node with it.
1516+
ReplaceNode(Node, UpdatedNode);
1517+
Node = UpdatedNode;
1518+
}
15131519
}
15141520
break;
15151521
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; This function contains two selects which differ only by having reversed
2+
; operand order. They are in fact equivalent, since the icmps that preceede
3+
; them also are the same except for reversed conditions. SelectionDAG will
4+
; discover this and return the other SELECT_CCMASK when the operands are
5+
; canonicalized. This must be handled by SystemZDAGToDAGISel::Select, or
6+
; instruction selection will fail.
7+
;
8+
; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13
9+
10+
11+
@g_1531 = external global [7 x i64], align 8
12+
@g_277 = external global <{ i64, i8, i8, i8, i8, i8, i8 }>, align 8
13+
@g_62.6 = external global i32, align 4
14+
15+
define dso_local void @fun() {
16+
entry:
17+
%tmp = add nuw nsw i16 0, 238
18+
%tmp4 = sub nsw i16 %tmp, 0
19+
store i64 4, i64* getelementptr inbounds (<{ i64, i8, i8, i8, i8, i8, i8 }>, <{ i64, i8, i8, i8, i8, i8, i8 }>* @g_277, i64 0, i32 0), align 8
20+
%tmp5 = load i64, i64* getelementptr inbounds ([7 x i64], [7 x i64]* @g_1531, i64 0, i64 5), align 8
21+
%tmp6 = trunc i64 %tmp5 to i32
22+
%tmp7 = trunc i64 %tmp5 to i16
23+
%tmp8 = shl i32 %tmp6, 24
24+
%tmp9 = ashr exact i32 %tmp8, 24
25+
%tmp10 = urem i16 %tmp7, %tmp4
26+
%tmp11 = icmp eq i16 %tmp10, 0
27+
%tmp12 = select i1 %tmp11, i32 0, i32 %tmp9
28+
%tmp13 = icmp sge i32 %tmp12, undef
29+
%tmp14 = zext i1 %tmp13 to i32
30+
%tmp15 = or i32 0, %tmp14
31+
%tmp16 = icmp ne i16 %tmp10, 0
32+
%tmp17 = select i1 %tmp16, i32 %tmp9, i32 0
33+
%tmp18 = icmp sge i32 %tmp17, undef
34+
%tmp19 = zext i1 %tmp18 to i32
35+
%tmp20 = or i32 %tmp15, %tmp19
36+
store i32 %tmp20, i32* @g_62.6, align 4
37+
unreachable
38+
}

0 commit comments

Comments
 (0)