From 8866583953f1e9038b5ca4ed4c199e0476790e0c Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 1 Jan 2021 02:21:53 +0300 Subject: [PATCH] [SimplifyCFG] Teach FoldValueComparisonIntoPredecessors() to preserve DomTree, part 2 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 2 ++ llvm/test/Transforms/PGOProfile/chr.ll | 2 +- llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll | 2 +- llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 2ff576b17751..bf61d34f7322 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1109,6 +1109,8 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI, std::vector Updates; + Updates.push_back({DominatorTree::Delete, Pred, BB}); + // Figure out which 'cases' to copy from SI to PSI. std::vector BBCases; BasicBlock *BBDefault = GetValueEqualityComparisonCases(TI, BBCases); diff --git a/llvm/test/Transforms/PGOProfile/chr.ll b/llvm/test/Transforms/PGOProfile/chr.ll index 0390b8eeee7d..8a05a624209e 100644 --- a/llvm/test/Transforms/PGOProfile/chr.ll +++ b/llvm/test/Transforms/PGOProfile/chr.ll @@ -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,function(chr,instcombine,simplify-cfg)' -S | FileCheck %s declare void @foo() diff --git a/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll b/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll index 2e356df75ca2..108fa3094add 100644 --- a/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll +++ b/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll @@ -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" diff --git a/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll b/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll index 0df40349c1b3..e1095431f31f 100644 --- a/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll +++ b/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll @@ -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.