Skip to content

Commit 6c81196

Browse files
committed
[SelectionDAG] Peek through freeze to see XOR
1 parent f675775 commit 6c81196

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10016,8 +10016,15 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
1001610016
}
1001710017
}
1001810018

10019+
auto PeekThroughFreeze = [](SDValue N) {
10020+
if (N->getOpcode() == ISD::FREEZE && N.hasOneUse())
10021+
return N->getOperand(0);
10022+
return N;
10023+
};
10024+
1001910025
// fold (xor x, x) -> 0
10020-
if (N0 == N1)
10026+
// FIXME: Refactor this and sub and other similar operations together.
10027+
if (PeekThroughFreeze(N0) == PeekThroughFreeze(N1))
1002110028
return tryFoldToZero(DL, TLI, VT, DAG, LegalOperations);
1002210029

1002310030
// fold (xor (shl 1, x), -1) -> (rotl ~1, x)

llvm/test/CodeGen/X86/freeze-simplify.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ define i32 @sub_freeze_2(i32 %x, i32 %y) {
2626
define i32 @xor_freeze(i32 %x, i32 %y) {
2727
; X86ASM-LABEL: xor_freeze:
2828
; X86ASM: # %bb.0:
29-
; X86ASM-NEXT: movl %edi, %eax
30-
; X86ASM-NEXT: xorl %edx, %edx
31-
; X86ASM-NEXT: divl %esi
3229
; X86ASM-NEXT: xorl %eax, %eax
3330
; X86ASM-NEXT: retq
3431
%a = udiv i32 %x, %y

0 commit comments

Comments
 (0)