llvm.org GIT mirror llvm / e6bdfcf
[CGP] Fix the remove of matched phis in complex addressing mode When we replace the Phi we created with matched ones it is possible that there are two identical phi nodes in IR. And matcher is smart enough to find that new created phi matches both of them. So we try to replace our phi node with matched ones twice and what is bad we delete our phi node twice causing a crash. As soon as we found that we have two identical Phi nodes it makes sense to do a clean-up and replace one phi node by other one. The patch implements it. Reviewers: john.brawn, reames Reviewed By: john.brawn Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D43758 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327250 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 1 year, 8 months ago
2 changed file(s) with 40 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
29452945 Matched.clear();
29462946 }
29472947 if (IsMatched) {
2948 // If we matched phi node to different but identical phis then
2949 // make a simplification here.
2950 DenseMap MatchedPHINodeMapping;
2951 for (auto MV : Matched) {
2952 auto AlreadyMatched = MatchedPHINodeMapping.find(MV.first);
2953 if (AlreadyMatched != MatchedPHINodeMapping.end()) {
2954 MV.second->replaceAllUsesWith(AlreadyMatched->second);
2955 ST.Put(MV.second, AlreadyMatched->second);
2956 MV.second->eraseFromParent();
2957 } else
2958 MatchedPHINodeMapping.insert({ MV.first, MV.second });
2959 }
29482960 // Replace all matched values and erase them.
2949 for (auto MV : Matched) {
2961 for (auto MV : MatchedPHINodeMapping) {
29502962 MV.first->replaceAllUsesWith(MV.second);
29512963 PhiNodesToMatch.erase(MV.first);
29522964 ST.Put(MV.first, MV.second);
0 ; RUN: opt -S -codegenprepare -disable-complex-addr-modes=false %s | FileCheck %s --check-prefix=CHECK
1 target datalayout =
2 "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 define void @test() {
6 entry:
7 %0 = getelementptr inbounds i64, i64 * null, i64 undef
8 br label %start
9
10 start:
11 %val1 = phi i64 * [ %0, %entry ], [ %val4, %exit ]
12 %val2 = phi i64 * [ null, %entry ], [ %val5, %exit ]
13 br i1 false, label %slowpath, label %exit
14
15 slowpath:
16 %elem1 = getelementptr inbounds i64, i64 * undef, i64 undef
17 br label %exit
18
19 exit:
20 ; CHECK: sunkaddr
21 %val3 = phi i64 * [ undef, %slowpath ], [ %val2, %start ]
22 %val4 = phi i64 * [ %elem1, %slowpath ], [ %val1, %start ]
23 %val5 = phi i64 * [ undef, %slowpath ], [ %val2, %start ]
24 %loadx = load i64, i64 * %val4, align 8
25 br label %start
26 }