[SimplifyCFG] Teach FoldValueComparisonIntoPredecessors() to preserve DomTree, part 2
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 31 Dec 2020 23:21:53 +0000 (02:21 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 1 Jan 2021 00:25:24 +0000 (03:25 +0300)
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/PGOProfile/chr.ll
llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll

index 2ff576b..bf61d34 100644 (file)
@@ -1109,6 +1109,8 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
 
       std::vector<DominatorTree::UpdateType> Updates;
 
+      Updates.push_back({DominatorTree::Delete, Pred, BB});
+
       // Figure out which 'cases' to copy from SI to PSI.
       std::vector<ValueEqualityComparisonCase> BBCases;
       BasicBlock *BBDefault = GetValueEqualityComparisonCases(TI, BBCases);
index 0390b8e..8a05a62 100644 (file)
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -chr -instcombine -simplifycfg -S -enable-new-pm=0 | FileCheck %s
+; RUN: opt < %s -chr -instcombine -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -enable-new-pm=0 | FileCheck %s
 ; RUN: opt < %s -passes='require<profile-summary>,function(chr,instcombine,simplify-cfg)' -S | FileCheck %s
 
 declare void @foo()
index 2e356df..108fa30 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | not grep icmp
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -hoist-common-insts=true | not grep icmp
 ; ModuleID = '/tmp/x.bc'
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
 target triple = "i686-pc-linux-gnu"
index 0df4034..e109543 100644 (file)
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
 
 ; Test that a switch going to a switch on the same value can be merged.
 ; All three switches in this example can be merged into one big one.