diff options
author | Hongbin Zheng <etherzhhb@gmail.com> | 2017-09-29 16:32:12 +0000 |
---|---|---|
committer | Hongbin Zheng <etherzhhb@gmail.com> | 2017-09-29 16:32:12 +0000 |
commit | c8abdf5f2509067052e5845d3d8a0e21020f628a (patch) | |
tree | b3d7372733104c0e88404b5d0904d49f9c939e30 /llvm | |
parent | c2e79c2dfc07e1aba27946f22ea370cd5c130b04 (diff) | |
download | bcm5719-llvm-c8abdf5f2509067052e5845d3d8a0e21020f628a.tar.gz bcm5719-llvm-c8abdf5f2509067052e5845d3d8a0e21020f628a.zip |
[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
llvm-svn: 314531
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 27 | ||||
-rw-r--r-- | llvm/test/Transforms/IndVarSimplify/constant-fold-1.ll | 39 | ||||
-rw-r--r-- | llvm/test/Transforms/IndVarSimplify/constant-fold.ll | 2 |
3 files changed, 57 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index cef8fe1a614..96088145bbc 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -546,18 +546,25 @@ bool SimplifyIndvar::foldConstantSCEV(Instruction *I) { const Loop *L = LI->getLoopFor(I->getParent()); S = SE->getSCEVAtScope(S, L); + auto *C = dyn_cast<SCEVConstant>(S); - if (auto *C = dyn_cast<SCEVConstant>(S)) { - I->replaceAllUsesWith(C->getValue()); - DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I - << " with constant: " << *C << '\n'); - ++NumFoldedUser; - Changed = true; - DeadInsts.emplace_back(I); - return true; - } + if (!C) + return false; - return false; + Constant *V = C->getValue(); + // The SCEV will have a different type than the instruction if the instruction + // has a pointer type. Skip the replacement + // TODO: Replace ConstantInt Zero by ConstantPointerNull + if (V->getType() != I->getType()) + return false; + + I->replaceAllUsesWith(V); + DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I << " with constant: " << *C + << '\n'); + ++NumFoldedUser; + Changed = true; + DeadInsts.emplace_back(I); + return true; } /// Eliminate any operation that SCEV can prove is an identity function. diff --git a/llvm/test/Transforms/IndVarSimplify/constant-fold-1.ll b/llvm/test/Transforms/IndVarSimplify/constant-fold-1.ll new file mode 100644 index 00000000000..a1ab41d0130 --- /dev/null +++ b/llvm/test/Transforms/IndVarSimplify/constant-fold-1.ll @@ -0,0 +1,39 @@ +; RUN: opt < %s -indvars -S | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @test(i64* %arg) unnamed_addr align 2 { +bb: + switch i64 undef, label %bb1 [ + ] + +bb1: ; preds = %bb + br label %bb2 + +bb2: ; preds = %bb6, %bb1 + %tmp = phi i64* [%arg, %bb1 ], [ %tmp7, %bb6 ] + switch i2 undef, label %bb6 [ + i2 1, label %bb5 + i2 -2, label %bb3 + i2 -1, label %bb3 + ] + +bb3: ; preds = %bb2, %bb2 + %tmp4 = call fastcc i32* @wobble(i64* nonnull %tmp, i32* null) + %tmp5 = load i32, i32* %tmp4 , align 8 + br label %bb6 + +bb5: ; preds = %bb2 + unreachable + +bb6: ; preds = %bb3, %bb2 + %tmp7 = load i64*, i64** undef, align 8 + br label %bb2 +} + +declare i32* @wobble(i64*, i32* returned) + +; Should not fail when SCEV is fold to ConstantPointerNull +; CHECK-LABEL: void @test +; CHECK: load i32, i32* %{{[a-zA-Z$._0-9]+}} diff --git a/llvm/test/Transforms/IndVarSimplify/constant-fold.ll b/llvm/test/Transforms/IndVarSimplify/constant-fold.ll index a35349aa1f5..ef42ac7dc78 100644 --- a/llvm/test/Transforms/IndVarSimplify/constant-fold.ll +++ b/llvm/test/Transforms/IndVarSimplify/constant-fold.ll @@ -19,7 +19,7 @@ for.end: ; preds = %for.inc } ; Should fold the condition of the select into constant -; CHECK-LABEL: void @test +; CHECK-LABEL: void @test0( ; CHECK: icmp eq i32 0, 0 define void @test1(i32* %a) { |