llvm.org GIT mirror llvm / a44ee67
[Reassociation] Place moved instructions after landing pads Reassociation's NegateValue moved instructions to the beginning of blocks (after PHIs) without checking for exception handling pads. It's possible for reassociation to move something into an exception handling block so we need to make sure we don't move things too early in the block. This change advances the insertion point past any exception handling pads. If the block we want to move into contains a catchswitch, we cannot move into it. In that case just create a new neg as if we had not found an existing neg to move. Differential Revision: https://reviews.llvm.org/D61089 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360262 91177308-0d34-0410-b5e6-96231b3b80d8 David Greene 4 months ago
3 changed file(s) with 118 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
860860 if (TheNeg->getParent()->getParent() != BI->getParent()->getParent())
861861 continue;
862862
863 bool FoundCatchSwitch = false;
864
863865 BasicBlock::iterator InsertPt;
864866 if (Instruction *InstInput = dyn_cast(V)) {
865867 if (InvokeInst *II = dyn_cast(InstInput)) {
867869 } else {
868870 InsertPt = ++InstInput->getIterator();
869871 }
870 while (isa(InsertPt)) ++InsertPt;
872
873 const BasicBlock *BB = InsertPt->getParent();
874
875 // Make sure we don't move anything before PHIs or exception
876 // handling pads.
877 while (InsertPt != BB->end() && (isa(InsertPt) ||
878 InsertPt->isEHPad())) {
879 if (isa(InsertPt))
880 // A catchswitch cannot have anything in the block except
881 // itself and PHIs. We'll bail out below.
882 FoundCatchSwitch = true;
883 ++InsertPt;
884 }
871885 } else {
872886 InsertPt = TheNeg->getParent()->getParent()->getEntryBlock().begin();
873887 }
888
889 // We found a catchswitch in the block where we want to move the
890 // neg. We cannot move anything into that block. Bail and just
891 // create the neg before BI, as if we hadn't found an existing
892 // neg.
893 if (FoundCatchSwitch)
894 break;
895
874896 TheNeg->moveBefore(&*InsertPt);
875897 if (TheNeg->getOpcode() == Instruction::Sub) {
876898 TheNeg->setHasNoUnsignedWrap(false);
0 ; ModuleID = 'bugpoint-reduced-simplified.bc'
1 source_filename = "catchswitch.cpp"
2 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-pc-windows-msvc19.11.0"
4
5 define dso_local void @"?f@@YAX_N@Z"(i1 %b) local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
6 entry:
7 br i1 %b, label %if.then, label %if.else
8
9 if.then: ; preds = %entry
10 invoke void @"?g@@YAXXZ"()
11 to label %cleanup unwind label %catch.dispatch
12
13 if.else: ; preds = %entry
14 invoke void @"?g2@@YAXXZ"()
15 to label %cleanup unwind label %catch.dispatch
16
17 catch.dispatch: ; preds = %if.else, %if.then
18 %z.0 = phi i32 [ 3, %if.then ], [ 5, %if.else ]
19 %0 = catchswitch within none [label %catch] unwind to caller
20
21 catch: ; preds = %catch.dispatch
22 %1 = catchpad within %0 [i8* null, i32 64, i8* null]
23 %blech = sub nsw i32 5, %z.0
24 %sub = sub nsw i32 %blech, %z.0
25 call void @"?use@@YAXHH@Z"(i32 %z.0, i32 %sub) [ "funclet"(token %1) ]
26 unreachable
27
28 cleanup: ; preds = %if.else, %if.then
29 ret void
30 }
31
32 declare dso_local void @"?g@@YAXXZ"() local_unnamed_addr #0
33
34 declare dso_local i32 @__CxxFrameHandler3(...)
35
36 declare dso_local void @"?g2@@YAXXZ"() local_unnamed_addr #0
37
38 declare dso_local void @"?use@@YAXHH@Z"(i32, i32) local_unnamed_addr #0
39
40 attributes #0 = { "use-soft-float"="false" }
0 ; Reassociate used to move the negation of $time_1_P14.0 above the
1 ; landingpad.
2 ;
3 ; RUN: opt -reassociate -disable-output < %s
4 ;
5 ; ModuleID = 'bugpoint-reduced-simplified.bc'
6 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux-gnu"
8
9 %"lp.2234.4378.7378.12512.15079.17646.20213.22780.25347.27914.40747.53580.74113.76680.86947.89514.92081.94648.115163.130561" = type { i8*, i32 }
10 %__type_info.2235.4379.7379.12513.15080.17647.20214.22781.25348.27915.40748.53581.74114.76681.86948.89515.92082.94649.115162.130560 = type { i64*, i8* }
11
12 declare i32 @__gxx_personality_v0(...)
13
14 declare void @b() #0
15
16 define void @a() #0 personality i32 (...)* @__gxx_personality_v0 {
17 ", bb1":
18 invoke void @b()
19 to label %invoke.cont unwind label %"bb22"
20
21 ", bb8": ; preds = %invoke.cont
22 invoke void @c()
23 to label %invoke.cont25 unwind label %"bb22"
24
25 ", bb15": ; preds = %invoke.cont
26 ret void
27
28 "bb22": ; preds = %", bb8", %", bb1"
29 %"$time_1_P14.0" = phi i64 [ undef, %", bb8" ], [ undef, %", bb1" ]
30 %0 = landingpad %"lp.2234.4378.7378.12512.15079.17646.20213.22780.25347.27914.40747.53580.74113.76680.86947.89514.92081.94648.115163.130561"
31 cleanup
32 catch %__type_info.2235.4379.7379.12513.15080.17647.20214.22781.25348.27915.40748.53581.74114.76681.86948.89515.92082.94649.115162.130560* null
33 %r79 = sub i64 0, %"$time_1_P14.0"
34 %r81 = add i64 %r79, undef
35 %r93 = add i64 %r81, undef
36 %r95 = sub i64 %r93, %"$time_1_P14.0"
37 %r98 = icmp ult i64 %r95, undef
38 unreachable
39
40 invoke.cont: ; preds = %", bb1"
41 br i1 undef, label %", bb15", label %", bb8"
42
43 invoke.cont25: ; preds = %", bb8"
44 unreachable
45 }
46
47 declare void @c() #0
48
49 attributes #0 = { "no-frame-pointer-elim-non-leaf" }
50
51 !llvm.module.flags = !{!0}
52
53 !0 = !{i32 1, !"Debug Info Version", i32 3}