Skip to content

Commit 36d4f6d

Browse files
committed
[X86] Fold xor(zext(xor(x,c1)),c2) -> xor(zext(x),xor(zext(c1),c2))
Fixes PR47603 (second case) by extending rG89afec348dbd3e5078f176e978971ee2d3b5dec8
1 parent 2523fe8 commit 36d4f6d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46983,16 +46983,18 @@ static SDValue combineXor(SDNode *N, SelectionDAG &DAG,
4698346983
if (SDValue RV = foldXorTruncShiftIntoCmp(N, DAG))
4698446984
return RV;
4698546985

46986+
// Fold xor(zext(xor(x,c1)),c2) -> xor(zext(x),xor(zext(c1),c2))
4698646987
// Fold xor(truncate(xor(x,c1)),c2) -> xor(truncate(x),xor(truncate(c1),c2))
4698746988
// TODO: Under what circumstances could this be performed in DAGCombine?
46988-
if (N->getOperand(0).getOpcode() == ISD::TRUNCATE &&
46989+
if ((N->getOperand(0).getOpcode() == ISD::TRUNCATE ||
46990+
N->getOperand(0).getOpcode() == ISD::ZERO_EXTEND) &&
4698946991
N->getOperand(0).getOperand(0).getOpcode() == N->getOpcode() &&
4699046992
isa<ConstantSDNode>(N->getOperand(1)) &&
4699146993
isa<ConstantSDNode>(N->getOperand(0).getOperand(0).getOperand(1))) {
4699246994
SDLoc DL(N);
46993-
SDValue TruncateSrc = N->getOperand(0).getOperand(0);
46994-
SDValue LHS = DAG.getNode(ISD::TRUNCATE, DL, VT, TruncateSrc.getOperand(0));
46995-
SDValue RHS = DAG.getNode(ISD::TRUNCATE, DL, VT, TruncateSrc.getOperand(1));
46995+
SDValue TruncExtSrc = N->getOperand(0).getOperand(0);
46996+
SDValue LHS = DAG.getZExtOrTrunc(TruncExtSrc.getOperand(0), DL, VT);
46997+
SDValue RHS = DAG.getZExtOrTrunc(TruncExtSrc.getOperand(1), DL, VT);
4699646998
return DAG.getNode(ISD::XOR, DL, VT, LHS,
4699746999
DAG.getNode(ISD::XOR, DL, VT, RHS, N->getOperand(1)));
4699847000
}

llvm/test/CodeGen/X86/clz.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,6 @@ define i32 @PR47603_zext(i32 %a0, [32 x i8]* %a1) {
11051105
; X64-LABEL: PR47603_zext:
11061106
; X64: # %bb.0:
11071107
; X64-NEXT: bsrl %edi, %eax
1108-
; X64-NEXT: xorl $31, %eax
1109-
; X64-NEXT: xorq $31, %rax
11101108
; X64-NEXT: movsbl (%rsi,%rax), %eax
11111109
; X64-NEXT: retq
11121110
;

0 commit comments

Comments
 (0)