[llvm] 9541434 - [DAGCombiner] `visitFREEZE()`: gracefully handle node invalidation

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 10:54:03 PST 2023


Author: HanSheng Zhang
Date: 2023-01-13T21:53:29+03:00
New Revision: 95414345d54ea714aceafb125541555ece31e876

URL: https://github.com/llvm/llvm-project/commit/95414345d54ea714aceafb125541555ece31e876
DIFF: https://github.com/llvm/llvm-project/commit/95414345d54ea714aceafb125541555ece31e876.diff

LOG: [DAGCombiner] `visitFREEZE()`: gracefully handle node invalidation

When we freeze operands of an operation that we are trying to freeze,
doing so may invalidate the original SDValue. We should just re-fetch
it from the ISD::FREEZE node, because if we bail, we'd hopefully just
revisit the node and do that again.

Fixes https://github.com/llvm/llvm-project/issues/59891

Differential Revision: https://reviews.llvm.org/D141256

Added: 
    llvm/test/CodeGen/AArch64/pr59891-dagcombine-deleted-freeze.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index db7132819690e..0e9e423767d4a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -14384,6 +14384,10 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
     }
   }
 
+  // The whole node may have been updated, so the value we were holding
+  // may no longer be valid. Re-fetch the operand we're `freeze`ing.
+  N0 = N->getOperand(0);
+
   // Finally, recreate the node, it's operands were updated to use
   // frozen operands, so we just need to use it's "original" operands.
   SmallVector<SDValue> Ops(N0->op_begin(), N0->op_end());

diff  --git a/llvm/test/CodeGen/AArch64/pr59891-dagcombine-deleted-freeze.ll b/llvm/test/CodeGen/AArch64/pr59891-dagcombine-deleted-freeze.ll
new file mode 100644
index 0000000000000..2c74903e067ba
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/pr59891-dagcombine-deleted-freeze.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=aarch64 | FileCheck %s
+
+; Freezing operand of an operation that is being freezed
+; may invalidate the whole SDValue we were trying to originally freeze.
+define i8 @pr59891(i64 %0) {
+; CHECK-LABEL: pr59891:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    mov w0, wzr
+; CHECK-NEXT:    ret
+  %2 = freeze i64 %0
+  %3 = trunc i64 %2 to i1
+  %4 = trunc i64 %0 to i1
+  %5 = xor i1 %3, %4
+  %6 = freeze i1 %5
+  %7 = zext i1 %6 to i8
+  ret i8 %7
+}


        


More information about the llvm-commits mailing list