[llvm] r346335 - [NewGVN] Make sure we do not add a user to itself.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 7 09:20:07 PST 2018
Author: fhahn
Date: Wed Nov 7 09:20:07 2018
New Revision: 346335
URL: http://llvm.org/viewvc/llvm-project?rev=346335&view=rev
Log:
[NewGVN] Make sure we do not add a user to itself.
If we simplify an instruction to itself, we do not need to add a user to
itself. For congruence classes with a defining expression, we already
use a similar logic.
Fixes PR38259.
Reviewers: davide, efriedma, mcrosier
Reviewed By: davide
Differential Revision: https://reviews.llvm.org/D51168
Added:
llvm/trunk/test/Transforms/NewGVN/simp-to-self.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=346335&r1=346334&r2=346335&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Wed Nov 7 09:20:07 2018
@@ -1086,9 +1086,13 @@ const Expression *NewGVN::checkSimplific
CongruenceClass *CC = ValueToClass.lookup(V);
if (CC) {
if (CC->getLeader() && CC->getLeader() != I) {
- // Don't add temporary instructions to the user lists.
- if (!AllTempInstructions.count(I))
- addAdditionalUsers(V, I);
+ // If we simplified to something else, we need to communicate
+ // that we're users of the value we simplified to.
+ if (I != V) {
+ // Don't add temporary instructions to the user lists.
+ if (!AllTempInstructions.count(I))
+ addAdditionalUsers(V, I);
+ }
return createVariableOrConstant(CC->getLeader());
}
if (CC->getDefiningExpr()) {
Added: llvm/trunk/test/Transforms/NewGVN/simp-to-self.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/NewGVN/simp-to-self.ll?rev=346335&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/NewGVN/simp-to-self.ll (added)
+++ llvm/trunk/test/Transforms/NewGVN/simp-to-self.ll Wed Nov 7 09:20:07 2018
@@ -0,0 +1,27 @@
+; RUN: opt -S < %s -newgvn | FileCheck %s
+
+; CHECK-LABEL: for.cond:
+; CHECK-NEXT: %lv = load i32, i32* bitcast (i64* @a to i32*)
+; CHECK-NEXT: %bf.clear = and i32 %lv, -131072
+; CHECK-NEXT: %bf.set = or i32 1, %bf.clear
+; CHECK-NEXT: br i1 %bc, label %for.cond, label %exit
+ at a = external global i64
+
+define void @fn1(i1 %bc) {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.cond1.1, %entry
+ %tmp = phi i1 [ undef, %entry ], [ 1, %for.cond ]
+ %conv = zext i1 %tmp to i32
+ %lv = load i32, i32* bitcast (i64* @a to i32*)
+ %bf.clear = and i32 %lv, -131072
+ %bf.set = or i32 %conv, %bf.clear
+ %bf.clear.1 = and i32 %bf.set, -131072
+ %bf.set.1 = or i32 1, %bf.clear.1
+ br i1 %bc, label %for.cond, label %exit
+
+exit: ; preds = %for.cond1
+ store i32 %bf.set.1, i32* bitcast (i64* @a to i32*)
+ ret void
+}
More information about the llvm-commits
mailing list