[llvm] 4e83e59 - [GVN] Add missing ICF update
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 6 10:16:44 PDT 2021
Author: Arthur Eubanks
Date: 2021-04-06T10:13:42-07:00
New Revision: 4e83e59eb8f096c8399489c61c1db034814a76ba
URL: https://github.com/llvm/llvm-project/commit/4e83e59eb8f096c8399489c61c1db034814a76ba
DIFF: https://github.com/llvm/llvm-project/commit/4e83e59eb8f096c8399489c61c1db034814a76ba.diff
LOG: [GVN] Add missing ICF update
performScalarPREInsertion() inserts instructions into blocks that we
need to tell ImplicitControlFlowTracking about, otherwise the ICF cache
may be invalid.
Fixes PR49193.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D99909
Added:
llvm/test/Transforms/GVN/pr49193.ll
Modified:
llvm/lib/Transforms/Scalar/GVN.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 54623fd7cd825..8a50920c9d59d 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2466,6 +2466,8 @@ bool GVN::performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
Instr->setName(Instr->getName() + ".pre");
Instr->setDebugLoc(Instr->getDebugLoc());
+ ICF->insertInstructionTo(Instr, Pred);
+
unsigned Num = VN.lookupOrAdd(Instr);
VN.add(Instr, Num);
diff --git a/llvm/test/Transforms/GVN/pr49193.ll b/llvm/test/Transforms/GVN/pr49193.ll
new file mode 100644
index 0000000000000..3e37dbd01e1fa
--- /dev/null
+++ b/llvm/test/Transforms/GVN/pr49193.ll
@@ -0,0 +1,58 @@
+; RUN: opt -passes=gvn -S < %s | FileCheck %s
+
+ at a = external local_unnamed_addr global i32, align 4
+ at b = external local_unnamed_addr global i32, align 4
+
+; Function Attrs: nounwind readnone
+declare i32* @j() local_unnamed_addr #0
+
+; CHECK: define {{.*}}@k()
+
+define i64 @k() local_unnamed_addr {
+bb:
+ br i1 undef, label %bb10.preheader, label %bb3
+
+bb10.preheader: ; preds = %bb
+ br label %bb13
+
+bb3: ; preds = %bb
+ %i4 = load i32, i32* @a, align 4
+ %i5.not = icmp eq i32 %i4, 0
+ br label %bb7
+
+bb7: ; preds = %bb3
+ %i8 = tail call i32* @j()
+ br label %bb37
+
+bb13: ; preds = %bb34, %bb10.preheader
+ br i1 undef, label %bb30thread-pre-split, label %bb16
+
+bb16: ; preds = %bb13
+ %i17 = tail call i32* @j()
+ br i1 undef, label %bb22thread-pre-split, label %bb37.loopexit
+
+bb22thread-pre-split: ; preds = %bb16
+ br label %bb27
+
+bb27: ; preds = %bb22thread-pre-split
+ br i1 undef, label %bb30thread-pre-split, label %bb37.loopexit
+
+bb30thread-pre-split: ; preds = %bb27, %bb13
+ %i31.pr = load i32, i32* @a, align 4
+ %i32.not2 = icmp eq i32 %i31.pr, 0
+ br label %bb34
+
+bb34: ; preds = %bb30thread-pre-split
+ br i1 undef, label %bb37.loopexit, label %bb13
+
+bb37.loopexit: ; preds = %bb34, %bb27, %bb16
+ br label %bb37
+
+bb37: ; preds = %bb37.loopexit, %bb7
+ %i38 = load i32, i32* @a, align 4
+ store i32 %i38, i32* @b, align 4
+ %i39 = tail call i32* @j()
+ unreachable
+}
+
+attributes #0 = { nounwind readnone }
More information about the llvm-commits
mailing list