llvm.org GIT mirror llvm / 33bfd3f
[SimplifyIndVar] Do not fail when we constant fold an IV user to ConstantPointerNull The type of a SCEVConstant may not match the corresponding LLVM Value. In this case, we skip the constant folding for now. TODO: Replace ConstantInt Zero by ConstantPointerNull git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314531 91177308-0d34-0410-b5e6-96231b3b80d8 Hongbin Zheng 2 years ago
3 changed file(s) with 59 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
545545
546546 const Loop *L = LI->getLoopFor(I->getParent());
547547 S = SE->getSCEVAtScope(S, L);
548
549 if (auto *C = dyn_cast(S)) {
550 I->replaceAllUsesWith(C->getValue());
551 DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I
552 << " with constant: " << *C << '\n');
553 ++NumFoldedUser;
554 Changed = true;
555 DeadInsts.emplace_back(I);
556 return true;
557 }
558
559 return false;
548 auto *C = dyn_cast(S);
549
550 if (!C)
551 return false;
552
553 Constant *V = C->getValue();
554 // The SCEV will have a different type than the instruction if the instruction
555 // has a pointer type. Skip the replacement
556 // TODO: Replace ConstantInt Zero by ConstantPointerNull
557 if (V->getType() != I->getType())
558 return false;
559
560 I->replaceAllUsesWith(V);
561 DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I << " with constant: " << *C
562 << '\n');
563 ++NumFoldedUser;
564 Changed = true;
565 DeadInsts.emplace_back(I);
566 return true;
560567 }
561568
562569 /// Eliminate any operation that SCEV can prove is an identity function.
0 ; RUN: opt < %s -indvars -S | FileCheck %s
1
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 define void @test(i64* %arg) unnamed_addr align 2 {
6 bb:
7 switch i64 undef, label %bb1 [
8 ]
9
10 bb1: ; preds = %bb
11 br label %bb2
12
13 bb2: ; preds = %bb6, %bb1
14 %tmp = phi i64* [%arg, %bb1 ], [ %tmp7, %bb6 ]
15 switch i2 undef, label %bb6 [
16 i2 1, label %bb5
17 i2 -2, label %bb3
18 i2 -1, label %bb3
19 ]
20
21 bb3: ; preds = %bb2, %bb2
22 %tmp4 = call fastcc i32* @wobble(i64* nonnull %tmp, i32* null)
23 %tmp5 = load i32, i32* %tmp4 , align 8
24 br label %bb6
25
26 bb5: ; preds = %bb2
27 unreachable
28
29 bb6: ; preds = %bb3, %bb2
30 %tmp7 = load i64*, i64** undef, align 8
31 br label %bb2
32 }
33
34 declare i32* @wobble(i64*, i32* returned)
35
36 ; Should not fail when SCEV is fold to ConstantPointerNull
37 ; CHECK-LABEL: void @test
38 ; CHECK: load i32, i32* %{{[a-zA-Z$._0-9]+}}
1818 }
1919
2020 ; Should fold the condition of the select into constant
21 ; CHECK-LABEL: void @test
21 ; CHECK-LABEL: void @test0(
2222 ; CHECK: icmp eq i32 0, 0
2323
2424 define void @test1(i32* %a) {