Skip to content

Commit 491a91e

Browse files
nikictru
authored andcommitted
[PowerPC] Use zext instead of anyext in custom and combine (#68784)
This custom combine currently converts `and(anyext(x),c)` into `anyext(and(x,c))`. This is not correct, because the original expression guaranteed that the high bits are zero, while the new one sets them to undef. Emit `zext(and(x,c))` instead. Fixes #68783. (cherry picked from commit 127ed9a)
1 parent 8ce6b65 commit 491a91e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15527,7 +15527,7 @@ SDValue PPCTargetLowering::PerformDAGCombine(SDNode *N,
1552715527
break;
1552815528
SDValue ConstOp = DAG.getConstant(Imm, dl, MVT::i32);
1552915529
SDValue NarrowAnd = DAG.getNode(ISD::AND, dl, MVT::i32, NarrowOp, ConstOp);
15530-
return DAG.getAnyExtOrTrunc(NarrowAnd, dl, N->getValueType(0));
15530+
return DAG.getZExtOrTrunc(NarrowAnd, dl, N->getValueType(0));
1553115531
}
1553215532
case ISD::SHL:
1553315533
return combineSHL(N, DCI);

llvm/test/CodeGen/PowerPC/and-extend-combine.ll

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ bb:
2323
ret ptr %i8
2424
}
2525

26-
; FIXME: This is a miscompile.
2726
define void @pr68783(i32 %x, ptr %p) {
2827
; CHECK-LABEL: pr68783:
2928
; CHECK: # %bb.0:
29+
; CHECK-NEXT: li r5, 0
3030
; CHECK-NEXT: rlwinm r3, r3, 31, 24, 31
31+
; CHECK-NEXT: sth r5, 4(r4)
3132
; CHECK-NEXT: stw r3, 0(r4)
3233
; CHECK-NEXT: blr
3334
%lshr = lshr i32 %x, 1

0 commit comments

Comments
 (0)