1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[X86] Fold xor(zext(xor(x,c1)),c2) -> xor(zext(x),xor(zext(c1),c2))

Fixes PR47603 (second case) by extending rG89afec348dbd3e5078f176e978971ee2d3b5dec8
This commit is contained in:
Simon Pilgrim 2021-04-05 11:40:29 +01:00
parent e9442d18f5
commit bda128cecc
2 changed files with 6 additions and 6 deletions

View File

@ -46983,16 +46983,18 @@ static SDValue combineXor(SDNode *N, SelectionDAG &DAG,
if (SDValue RV = foldXorTruncShiftIntoCmp(N, DAG))
return RV;
// Fold xor(zext(xor(x,c1)),c2) -> xor(zext(x),xor(zext(c1),c2))
// Fold xor(truncate(xor(x,c1)),c2) -> xor(truncate(x),xor(truncate(c1),c2))
// TODO: Under what circumstances could this be performed in DAGCombine?
if (N->getOperand(0).getOpcode() == ISD::TRUNCATE &&
if ((N->getOperand(0).getOpcode() == ISD::TRUNCATE ||
N->getOperand(0).getOpcode() == ISD::ZERO_EXTEND) &&
N->getOperand(0).getOperand(0).getOpcode() == N->getOpcode() &&
isa<ConstantSDNode>(N->getOperand(1)) &&
isa<ConstantSDNode>(N->getOperand(0).getOperand(0).getOperand(1))) {
SDLoc DL(N);
SDValue TruncateSrc = N->getOperand(0).getOperand(0);
SDValue LHS = DAG.getNode(ISD::TRUNCATE, DL, VT, TruncateSrc.getOperand(0));
SDValue RHS = DAG.getNode(ISD::TRUNCATE, DL, VT, TruncateSrc.getOperand(1));
SDValue TruncExtSrc = N->getOperand(0).getOperand(0);
SDValue LHS = DAG.getZExtOrTrunc(TruncExtSrc.getOperand(0), DL, VT);
SDValue RHS = DAG.getZExtOrTrunc(TruncExtSrc.getOperand(1), DL, VT);
return DAG.getNode(ISD::XOR, DL, VT, LHS,
DAG.getNode(ISD::XOR, DL, VT, RHS, N->getOperand(1)));
}

View File

@ -1105,8 +1105,6 @@ define i32 @PR47603_zext(i32 %a0, [32 x i8]* %a1) {
; X64-LABEL: PR47603_zext:
; X64: # %bb.0:
; X64-NEXT: bsrl %edi, %eax
; X64-NEXT: xorl $31, %eax
; X64-NEXT: xorq $31, %rax
; X64-NEXT: movsbl (%rsi,%rax), %eax
; X64-NEXT: retq
;