[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
Fri Jul 2 05:14:34 PDT 2021


aqjune updated this revision to Diff 356154.
aqjune added a comment.

clang-format


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
@@ -10152,9 +10152,30 @@
   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 (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.356154.patch
Type: text/x-patch
Size: 1889 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210702/06f913da/attachment.bin>


More information about the llvm-commits mailing list