[DAG] DAGCombiner::foldSelectOfBinops - propagate the common flags to the merged binop

As discussed on D106058 - we were failing to keep the common flags. This matches the behaviour in InstCombinerImpl::foldSelectOpOp.
This commit is contained in:
Simon Pilgrim 2021-07-18 18:38:48 +01:00
parent 5643be96bc
commit fd7a54c709
2 changed files with 8 additions and 3 deletions

View File

@ -22390,7 +22390,10 @@ SDValue DAGCombiner::foldSelectOfBinops(SDNode *N) {
if (N1.getOperand(1) == N2.getOperand(1)) {
SDValue NewSel =
DAG.getSelect(DL, VT, N0, N1.getOperand(0), N2.getOperand(0));
return DAG.getNode(BinOpc, DL, VT, NewSel, N1.getOperand(1));
SDValue NewBinOp = DAG.getNode(BinOpc, DL, VT, NewSel, N1.getOperand(1));
NewBinOp->setFlags(N1->getFlags());
NewBinOp->intersectFlagsWith(N2->getFlags());
return NewBinOp;
}
// Fold select(cond, binop(x, y), binop(x, z))
@ -22401,7 +22404,10 @@ SDValue DAGCombiner::foldSelectOfBinops(SDNode *N) {
VT == N2.getOperand(1).getValueType()) {
SDValue NewSel =
DAG.getSelect(DL, VT, N0, N1.getOperand(1), N2.getOperand(1));
return DAG.getNode(BinOpc, DL, VT, N1.getOperand(0), NewSel);
SDValue NewBinOp = DAG.getNode(BinOpc, DL, VT, N1.getOperand(0), NewSel);
NewBinOp->setFlags(N1->getFlags());
NewBinOp->intersectFlagsWith(N2->getFlags());
return NewBinOp;
}
// TODO: Handle isCommutativeBinOp patterns as well?

View File

@ -474,7 +474,6 @@ define i32 @combine_shl_ge_sel_ashr_extact0(i32 %x, i32 %y, i32 %z) {
; CHECK-NEXT: testl %edx, %edx
; CHECK-NEXT: cmovel %esi, %edi
; CHECK-NEXT: leal (,%rdi,4), %eax
; CHECK-NEXT: andl $-32, %eax
; CHECK-NEXT: retq
%cmp = icmp ne i32 %z, 0
%ashrx = ashr exact i32 %x, 3