[PATCH] D75398: [GVN] Fold equivalent freeze instructions

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 28 22:01:45 PST 2020


aqjune created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

This patch defines two freeze instructions to have the same value number if they are equivalent.

This is allowed because GVN replaces all uses of a duplicated instruction with another.

If it partially rewrites use, it is not allowed. e.g)

  a = freeze(x)
  b = freeze(x)
  use(a)
  use(a)
  use(b)
  =>
  use(a)
  use(b) // This is not allowed!
  use(b)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75398

Files:
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/test/Transforms/GVN/freeze.ll


Index: llvm/test/Transforms/GVN/freeze.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GVN/freeze.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -gvn -S | FileCheck %s
+; RUN: opt < %s -passes=gvn -S | FileCheck %s
+
+define i1 @f(i1 %a) {
+; CHECK-LABEL: @f(
+; CHECK-NEXT:    [[B:%.*]] = freeze i1 [[A:%.*]]
+; CHECK-NEXT:    ret i1 [[B]]
+;
+  %b = freeze i1 %a
+  %c = freeze i1 %a
+  %d = and i1 %b, %b
+  ret i1 %d
+}
Index: llvm/lib/Transforms/Scalar/GVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVN.cpp
+++ llvm/lib/Transforms/Scalar/GVN.cpp
@@ -531,6 +531,7 @@
     case Instruction::AddrSpaceCast:
     case Instruction::BitCast:
     case Instruction::Select:
+    case Instruction::Freeze:
     case Instruction::ExtractElement:
     case Instruction::InsertElement:
     case Instruction::ShuffleVector:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75398.247407.patch
Type: text/x-patch
Size: 1006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200229/756af15f/attachment.bin>


More information about the llvm-commits mailing list