[PATCH] D20462: Functions with differing phis should not be merged.

Mark Lacey via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 11:45:38 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL270250: Functions with differing phis should not be merged. (authored by rudkx).

Changed prior to commit:
  http://reviews.llvm.org/D20462?vs=57957&id=57962#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20462

Files:
  llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
  llvm/trunk/test/Transforms/MergeFunc/phi-check-blocks.ll

Index: llvm/trunk/test/Transforms/MergeFunc/phi-check-blocks.ll
===================================================================
--- llvm/trunk/test/Transforms/MergeFunc/phi-check-blocks.ll
+++ llvm/trunk/test/Transforms/MergeFunc/phi-check-blocks.ll
@@ -0,0 +1,50 @@
+; RUN: opt -S -mergefunc < %s | FileCheck %s
+
+; Ensure that we do not merge functions that are identical with the
+; exception of the order of the incoming blocks to a phi.
+
+; CHECK-LABEL: define linkonce_odr hidden i1 @first(i2)
+define linkonce_odr hidden i1 @first(i2) {
+entry:
+; CHECK: switch i2
+  switch i2 %0, label %default [
+    i2 0, label %L1
+    i2 1, label %L2
+    i2 -2, label %L3
+  ]
+default:
+  unreachable
+L1:
+  br label %done
+L2:
+  br label %done
+L3:
+  br label %done
+done:
+  %result = phi i1 [ true, %L1 ], [ false, %L2 ], [ false, %L3 ]
+; CHECK: ret i1
+  ret i1 %result
+}
+
+; CHECK-LABEL: define linkonce_odr hidden i1 @second(i2)
+define linkonce_odr hidden i1 @second(i2) {
+entry:
+; CHECK: switch i2
+  switch i2 %0, label %default [
+    i2 0, label %L1
+    i2 1, label %L2
+    i2 -2, label %L3
+  ]
+default:
+  unreachable
+L1:
+  br label %done
+L2:
+  br label %done
+L3:
+  br label %done
+done:
+  %result = phi i1 [ true, %L3 ], [ false, %L2 ], [ false, %L1 ]
+; CHECK: ret i1
+  ret i1 %result
+}
Index: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
@@ -1050,6 +1050,17 @@
     return cmpNumbers(RMWI->getSynchScope(),
                       cast<AtomicRMWInst>(R)->getSynchScope());
   }
+  if (const PHINode *PNL = dyn_cast<PHINode>(L)) {
+    const PHINode *PNR = cast<PHINode>(R);
+    // Ensure that in addition to the incoming values being identical
+    // (checked by the caller of this function), the incoming blocks
+    // are also identical.
+    for (unsigned i = 0, e = PNL->getNumIncomingValues(); i != e; ++i) {
+      if (int Res =
+              cmpValues(PNL->getIncomingBlock(i), PNR->getIncomingBlock(i)))
+        return Res;
+    }
+  }
   return 0;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20462.57962.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160520/e4585a15/attachment.bin>


More information about the llvm-commits mailing list