[PATCH] D105344: [DAGCombiner] Fold SETCC(FREEZE(x), y) to SETCC(x, y) if used by BRCOND
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 3 10:18:30 PDT 2021
aqjune updated this revision to Diff 356347.
aqjune added a comment.
Update a comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105344/new/
https://reviews.llvm.org/D105344
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/setcc-freeze.ll
Index: llvm/test/CodeGen/X86/setcc-freeze.ll
===================================================================
--- llvm/test/CodeGen/X86/setcc-freeze.ll
+++ llvm/test/CodeGen/X86/setcc-freeze.ll
@@ -4,9 +4,7 @@
define i32 @f(i16* %p) {
; CHECK-LABEL: f:
; CHECK: # %bb.0:
-; CHECK-NEXT: movzwl (%rdi), %eax
-; CHECK-NEXT: andl $2048, %eax # imm = 0x800
-; CHECK-NEXT: testw %ax, %ax
+; CHECK-NEXT: testb $8, 1(%rdi)
; CHECK-NEXT: je .LBB0_1
; CHECK-NEXT: # %bb.2: # %B
; CHECK-NEXT: movl $20, %eax
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -10190,9 +10190,31 @@
bool PreferSetCC =
N->hasOneUse() && N->use_begin()->getOpcode() == ISD::BRCOND;
- SDValue Combined = SimplifySetCC(
- N->getValueType(0), N->getOperand(0), N->getOperand(1),
- cast<CondCodeSDNode>(N->getOperand(2))->get(), SDLoc(N), !PreferSetCC);
+ ISD::CondCode Cond = cast<CondCodeSDNode>(N->getOperand(2))->get();
+ EVT VT = N->getValueType(0);
+
+ // BRCOND(SETCC(FREEZE(a), b)) is equivalent to
+ // BRCOND(SETCC(a, b)) (both are nondeterministic jumps).
+ // if the SETCC is used by BRCOND only.
+ if (PreferSetCC) {
+ SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
+ bool Updated = false;
+
+ if (N0->getOpcode() == ISD::FREEZE && N0.hasOneUse()) {
+ N0 = N0->getOperand(0);
+ Updated = true;
+ }
+ if (N1->getOpcode() == ISD::FREEZE && N1.hasOneUse()) {
+ N1 = N1->getOperand(0);
+ Updated = true;
+ }
+
+ if (Updated)
+ return DAG.getSetCC(SDLoc(N), VT, N0, N1, Cond);
+ }
+
+ SDValue Combined = SimplifySetCC(VT, N->getOperand(0), N->getOperand(1), Cond,
+ SDLoc(N), !PreferSetCC);
if (!Combined)
return SDValue();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105344.356347.patch
Type: text/x-patch
Size: 1932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210703/7cd5050e/attachment.bin>
More information about the llvm-commits
mailing list