[PATCH] D47143: [NewGVN] Do not treat LoadExpressions with differing nonnull as equal.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 21 07:58:18 PDT 2018


fhahn created this revision.
fhahn added reviewers: dberlin, davide.
Herald added a subscriber: Prazek.

We should not put LoadExpressions with and without nonnull metadata in
the same congruence class. If the leader happens to have nonnull, but
some members do not have nonnull, some simplifications do not apply to
all members.

See https://bugs.llvm.org/show_bug.cgi?id=37540.


https://reviews.llvm.org/D47143

Files:
  lib/Transforms/Scalar/NewGVN.cpp
  test/Transforms/NewGVN/load-nonnull.ll


Index: test/Transforms/NewGVN/load-nonnull.ll
===================================================================
--- /dev/null
+++ test/Transforms/NewGVN/load-nonnull.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -S -newgvn | FileCheck %s
+
+; CHECK-LABEL: bb1:
+; CHECK-NEXT: %load1 = load {}*, {}** %arg
+; CHECK-NEXT: %cmp1 = icmp eq {}* %load1, null
+
+; CHECK-LABEL: bb2:
+; CHECK: ret i1 false
+
+define i1 @test({}** %arg, i1 %arg2) {
+  br i1 %arg2, label %bb1, label %bb2
+
+bb1:
+  %load1 = load {}*, {}** %arg
+  %cmp1 = icmp eq {}* %load1, null
+  ret i1 %cmp1
+
+bb2:
+  %load2 = load {}*, {}** %arg, !nonnull !1
+  %cmp2 = icmp eq {}* %load2, null
+  ret i1 %cmp2
+}
+
+!1 = !{}
Index: lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- lib/Transforms/Scalar/NewGVN.cpp
+++ lib/Transforms/Scalar/NewGVN.cpp
@@ -873,7 +873,13 @@
 }
 
 bool LoadExpression::equals(const Expression &Other) const {
-  return equalsLoadStoreHelper(*this, Other);
+  if (!equalsLoadStoreHelper(*this, Other))
+    return false;
+  // Check that the nonnull metadata agrees.
+  if (const auto *L = dyn_cast<LoadExpression>(&Other))
+    return Load->getMetadata(LLVMContext::MD_nonnull) ==
+           L->Load->getMetadata(LLVMContext::MD_nonnull);
+  return true;
 }
 
 bool StoreExpression::equals(const Expression &Other) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47143.147786.patch
Type: text/x-patch
Size: 1370 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180521/09848ac7/attachment.bin>


More information about the llvm-commits mailing list