[llvm] r314561 - Eliminate PHI (int typed) which has only one use by intptr

Evgenii Stepanov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 29 15:20:28 PDT 2017


This is crashing when building ASan tests:
clang-6.0: /code/llvm-project/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp:228:
llvm::Instruction
*llvm::InstCombiner::FoldIntegerTypedPHI(llvm::PHINode &): Assertion
`(isa<PHINode>(IncomingVal) || (LoadI && LoadI->hasOneUse())) && "Can
not replace LoadInst with multiple uses"' failed.
#0 0x0000000001d731e4 PrintStackTraceSignalHandler(void*)
(/code/build-llvm/bin/clang-6.0+0x1d731e4)
#1 0x0000000001d73506 SignalHandler(int)
(/code/build-llvm/bin/clang-6.0+0x1d73506)
#2 0x00007f61d4edd330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#3 0x00007f61d3accc37 gsignal
/build/eglibc-SvCtMH/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#4 0x00007f61d3ad0028 abort /build/eglibc-SvCtMH/eglibc-2.19/stdlib/abort.c:91:0
#5 0x00007f61d3ac5bf6 __assert_fail_base
/build/eglibc-SvCtMH/eglibc-2.19/assert/assert.c:92:0
#6 0x00007f61d3ac5ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#7 0x0000000001a514ea
llvm::InstCombiner::FoldIntegerTypedPHI(llvm::PHINode&)
(/code/build-llvm/bin/clang-6.0+0x1a514ea)
#8 0x0000000001a560a2 llvm::InstCombiner::visitPHINode(llvm::PHINode&)
(/code/build-llvm/bin/clang-6.0+0x1a560a2)
#9 0x00000000019db61b llvm::InstCombiner::run()
(/code/build-llvm/bin/clang-6.0+0x19db61b)
#10 0x00000000019dd5a7
combineInstructionsOverFunction(llvm::Function&,
llvm::InstCombineWorklist&, llvm::AAResults*, llvm::AssumptionCache&,
llvm::TargetLibraryInfo&, llvm::DominatorTree&,
llvm::OptimizationRemarkEmitter&, bool, llvm::LoopInfo*)
(/code/build-llvm/bin/clang-6.0+0x19dd5a7)
#11 0x00000000019ddc66
llvm::InstructionCombiningPass::runOnFunction(llvm::Function&)
(/code/build-llvm/bin/clang-6.0+0x19ddc66)
#12 0x00000000018cbb9f
llvm::FPPassManager::runOnFunction(llvm::Function&)
(/code/build-llvm/bin/clang-6.0+0x18cbb9f)
#13 0x0000000001387fc6 (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&)
(/code/build-llvm/bin/clang-6.0+0x1387fc6)
#14 0x00000000018cc2f5
llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/code/build-llvm/bin/clang-6.0+0x18cc2f5)
#15 0x0000000001f0838b
clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&,
llvm::DataLayout const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/code/build-llvm/bin/clang-6.0+0x1f0838b)
#16 0x00000000026763ce
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/code/build-llvm/bin/clang-6.0+0x26763ce)
#17 0x0000000002b25b96 clang::ParseAST(clang::Sema&, bool, bool)
(/code/build-llvm/bin/clang-6.0+0x2b25b96)
#18 0x0000000002319798 clang::FrontendAction::Execute()
(/code/build-llvm/bin/clang-6.0+0x2319798)
#19 0x00000000022c8841
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/code/build-llvm/bin/clang-6.0+0x22c8841)
#20 0x00000000023a7d6a
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/code/build-llvm/bin/clang-6.0+0x23a7d6a)
#21 0x00000000008686b4 cc1_main(llvm::ArrayRef<char const*>, char
const*, void*) (/code/build-llvm/bin/clang-6.0+0x8686b4)
#22 0x0000000000866214 main (/code/build-llvm/bin/clang-6.0+0x866214)

On Fri, Sep 29, 2017 at 3:10 PM, Xinliang David Li via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: davidxl
> Date: Fri Sep 29 15:10:15 2017
> New Revision: 314561
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314561&view=rev
> Log:
> Eliminate PHI (int typed) which has only one use by intptr
>
> This patch will eliminate redundant intptr/ptrtoint that pessimizes
> analyses such as SCEV, AA and will make optimization passes such
> as auto-vectorization more powerful.
>
> Differential revision: http://reviews.llvm.org/D37832
>
> Added:
>     llvm/trunk/test/Transforms/InstCombine/intptr1.ll
>     llvm/trunk/test/Transforms/InstCombine/intptr2.ll
>     llvm/trunk/test/Transforms/InstCombine/intptr3.ll
>     llvm/trunk/test/Transforms/InstCombine/intptr4.ll
> Modified:
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
>     llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=314561&r1=314560&r2=314561&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Fri Sep 29 15:10:15 2017
> @@ -670,6 +670,10 @@ private:
>    Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
>    Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
>    Instruction *FoldPHIArgZextsIntoPHI(PHINode &PN);
> +  /// If an integer typed PHI has only one use which is an IntToPtr operation,
> +  /// replace the PHI with an existing pointer typed PHI if it exists. Otherwise
> +  /// insert a new pointer typed PHI and replace the original one.
> +  Instruction *FoldIntegerTypedPHI(PHINode &PN);
>
>    /// Helper function for FoldPHIArgXIntoPHI() to get debug location for the
>    /// folded operation.
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp?rev=314561&r1=314560&r2=314561&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp Fri Sep 29 15:10:15 2017
> @@ -39,6 +39,222 @@ DebugLoc InstCombiner::PHIArgMergedDebug
>    return Loc;
>  }
>
> +// Replace Integer typed PHI PN if the PHI's value is used as a pointer value.
> +// If there is an existing pointer typed PHI that produces the same value as PN,
> +// replace PN and the IntToPtr operation with it. Otherwise, synthesize a new
> +// PHI node:
> +//
> +// Case-1:
> +// bb1:
> +//     int_init = PtrToInt(ptr_init)
> +//     br label %bb2
> +// bb2:
> +//    int_val = PHI([int_init, %bb1], [int_val_inc, %bb2]
> +//    ptr_val = PHI([ptr_init, %bb1], [ptr_val_inc, %bb2]
> +//    ptr_val2 = IntToPtr(int_val)
> +//    ...
> +//    use(ptr_val2)
> +//    ptr_val_inc = ...
> +//    inc_val_inc = PtrToInt(ptr_val_inc)
> +//
> +// ==>
> +// bb1:
> +//     br label %bb2
> +// bb2:
> +//    ptr_val = PHI([ptr_init, %bb1], [ptr_val_inc, %bb2]
> +//    ...
> +//    use(ptr_val)
> +//    ptr_val_inc = ...
> +//
> +// Case-2:
> +// bb1:
> +//    int_ptr = BitCast(ptr_ptr)
> +//    int_init = Load(int_ptr)
> +//    br label %bb2
> +// bb2:
> +//    int_val = PHI([int_init, %bb1], [int_val_inc, %bb2]
> +//    ptr_val2 = IntToPtr(int_val)
> +//    ...
> +//    use(ptr_val2)
> +//    ptr_val_inc = ...
> +//    inc_val_inc = PtrToInt(ptr_val_inc)
> +// ==>
> +// bb1:
> +//    ptr_init = Load(ptr_ptr)
> +//    br label %bb2
> +// bb2:
> +//    ptr_val = PHI([ptr_init, %bb1], [ptr_val_inc, %bb2]
> +//    ...
> +//    use(ptr_val)
> +//    ptr_val_inc = ...
> +//    ...
> +//
> +Instruction *InstCombiner::FoldIntegerTypedPHI(PHINode &PN) {
> +  if (!PN.getType()->isIntegerTy())
> +    return nullptr;
> +  if (!PN.hasOneUse())
> +    return nullptr;
> +
> +  auto *IntToPtr = dyn_cast<IntToPtrInst>(PN.user_back());
> +  if (!IntToPtr)
> +    return nullptr;
> +
> +  // Check if the pointer is actually used as pointer:
> +  auto HasPointerUse = [](Instruction *IIP) {
> +    for (User *U : IIP->users()) {
> +      Value *Ptr = nullptr;
> +      if (LoadInst *LoadI = dyn_cast<LoadInst>(U)) {
> +        Ptr = LoadI->getPointerOperand();
> +      } else if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
> +        Ptr = SI->getPointerOperand();
> +      } else if (GetElementPtrInst *GI = dyn_cast<GetElementPtrInst>(U)) {
> +        Ptr = GI->getPointerOperand();
> +      }
> +
> +      if (Ptr && Ptr == IIP)
> +        return true;
> +    }
> +    return false;
> +  };
> +
> +  if (!HasPointerUse(IntToPtr))
> +    return nullptr;
> +
> +  if (DL.getPointerSizeInBits(IntToPtr->getAddressSpace()) !=
> +      DL.getTypeSizeInBits(IntToPtr->getOperand(0)->getType()))
> +    return nullptr;
> +
> +  SmallVector<Value *, 4> AvailablePtrVals;
> +  for (unsigned i = 0; i != PN.getNumIncomingValues(); ++i) {
> +    Value *Arg = PN.getIncomingValue(i);
> +
> +    // First look backward:
> +    if (auto *PI = dyn_cast<PtrToIntInst>(Arg)) {
> +      AvailablePtrVals.emplace_back(PI->getOperand(0));
> +      continue;
> +    }
> +
> +    // Next look forward:
> +    Value *ArgIntToPtr = nullptr;
> +    for (User *U : Arg->users()) {
> +      if (isa<IntToPtrInst>(U) && U->getType() == IntToPtr->getType() &&
> +          (DT.dominates(cast<Instruction>(U), PN.getIncomingBlock(i)) ||
> +           cast<Instruction>(U)->getParent() == PN.getIncomingBlock(i))) {
> +        ArgIntToPtr = U;
> +        break;
> +      }
> +    }
> +
> +    if (ArgIntToPtr) {
> +      AvailablePtrVals.emplace_back(ArgIntToPtr);
> +      continue;
> +    }
> +
> +    // If Arg is defined by a PHI, allow it. This will also create
> +    // more opportunities iteratively.
> +    if (isa<PHINode>(Arg)) {
> +      AvailablePtrVals.emplace_back(Arg);
> +      continue;
> +    }
> +
> +    // For a single use integer load:
> +    auto *LoadI = dyn_cast<LoadInst>(Arg);
> +    if (!LoadI)
> +      return nullptr;
> +
> +    if (!LoadI->hasOneUse())
> +      return nullptr;
> +
> +    // Push the integer typed Load instruction into the available
> +    // value set, and fix it up later when the pointer typed PHI
> +    // is synthesized.
> +    AvailablePtrVals.emplace_back(LoadI);
> +  }
> +
> +  // Now search for a matching PHI
> +  auto *BB = PN.getParent();
> +  assert(AvailablePtrVals.size() == PN.getNumIncomingValues() &&
> +         "Not enough available ptr typed incoming values");
> +  PHINode *MatchingPtrPHI = nullptr;
> +  for (auto II = BB->begin(), EI = BasicBlock::iterator(BB->getFirstNonPHI());
> +       II != EI; II++) {
> +    PHINode *PtrPHI = dyn_cast<PHINode>(II);
> +    if (!PtrPHI || PtrPHI == &PN)
> +      continue;
> +    MatchingPtrPHI = PtrPHI;
> +    for (unsigned i = 0; i != PtrPHI->getNumIncomingValues(); ++i) {
> +      if (AvailablePtrVals[i] != PtrPHI->getIncomingValue(i)) {
> +        MatchingPtrPHI = nullptr;
> +        break;
> +      }
> +    }
> +
> +    if (MatchingPtrPHI)
> +      break;
> +  }
> +
> +  if (MatchingPtrPHI) {
> +    assert(MatchingPtrPHI->getType() == IntToPtr->getType() &&
> +           "Phi's Type does not match with IntToPtr");
> +    // The PtrToCast + IntToPtr will be simplified later
> +    return CastInst::CreateBitOrPointerCast(MatchingPtrPHI,
> +                                            IntToPtr->getOperand(0)->getType());
> +  }
> +
> +  // If it requires a conversion for every PHI operand, do not do it.
> +  if (std::all_of(AvailablePtrVals.begin(), AvailablePtrVals.end(),
> +                  [&](Value *V) {
> +                    return (V->getType() != IntToPtr->getType()) ||
> +                           isa<IntToPtrInst>(V);
> +                  }))
> +    return nullptr;
> +
> +  PHINode *NewPtrPHI = PHINode::Create(
> +      IntToPtr->getType(), PN.getNumIncomingValues(), PN.getName() + ".ptr");
> +
> +  InsertNewInstBefore(NewPtrPHI, PN);
> +  for (unsigned i = 0; i != PN.getNumIncomingValues(); ++i) {
> +    auto *IncomingBB = PN.getIncomingBlock(i);
> +    auto *IncomingVal = AvailablePtrVals[i];
> +
> +    if (IncomingVal->getType() == IntToPtr->getType()) {
> +      NewPtrPHI->addIncoming(IncomingVal, IncomingBB);
> +      continue;
> +    }
> +
> +#ifndef NDEBUG
> +    LoadInst *LoadI = dyn_cast<LoadInst>(IncomingVal);
> +    assert((isa<PHINode>(IncomingVal) || (LoadI && LoadI->hasOneUse())) &&
> +           "Can not replace LoadInst with multiple uses");
> +#endif
> +    // Need to insert a BitCast.
> +    // For an integer Load instruction with a single use, the load + IntToPtr
> +    // cast will be simplified into a pointer load:
> +    // %v = load i64, i64* %a.ip, align 8
> +    // %v.cast = inttoptr i64 %v to float **
> +    // ==>
> +    // %v.ptrp = bitcast i64 * %a.ip to float **
> +    // %v.cast = load float *, float ** %v.ptrp, align 8
> +    auto *CI = CastInst::CreateBitOrPointerCast(
> +        IncomingVal, IntToPtr->getType(), IncomingVal->getName() + ".ptr");
> +    if (auto *IncomingI = dyn_cast<Instruction>(IncomingVal)) {
> +      BasicBlock::iterator InsertPos(IncomingI);
> +      InsertPos++;
> +      if (isa<PHINode>(IncomingI))
> +        InsertPos = IncomingI->getParent()->getFirstInsertionPt();
> +      InsertNewInstBefore(CI, *InsertPos);
> +    } else {
> +      auto *InsertBB = &IncomingBB->getParent()->getEntryBlock();
> +      InsertNewInstBefore(CI, *InsertBB->getFirstInsertionPt());
> +    }
> +    NewPtrPHI->addIncoming(CI, IncomingBB);
> +  }
> +
> +  // The PtrToCast + IntToPtr will be simplified later
> +  return CastInst::CreateBitOrPointerCast(NewPtrPHI,
> +                                          IntToPtr->getOperand(0)->getType());
> +}
> +
>  /// If we have something like phi [add (a,b), add(a,c)] and if a/b/c and the
>  /// adds all have a single use, turn this into a phi and a single binop.
>  Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
> @@ -902,6 +1118,9 @@ Instruction *InstCombiner::visitPHINode(
>    // this PHI only has a single use (a PHI), and if that PHI only has one use (a
>    // PHI)... break the cycle.
>    if (PN.hasOneUse()) {
> +    if (Instruction *Result = FoldIntegerTypedPHI(PN))
> +      return Result;
> +
>      Instruction *PHIUser = cast<Instruction>(PN.user_back());
>      if (PHINode *PU = dyn_cast<PHINode>(PHIUser)) {
>        SmallPtrSet<PHINode*, 16> PotentiallyDeadPHIs;
>
> Added: llvm/trunk/test/Transforms/InstCombine/intptr1.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr1.ll?rev=314561&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/intptr1.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/intptr1.ll Fri Sep 29 15:10:15 2017
> @@ -0,0 +1,181 @@
> +; RUN: opt < %s  -instcombine  -S | FileCheck %s
> +
> +
> +define void @test1(float* %a, float* readnone %a_end, i64* %b.i64) {
> +; CHECK-LABEL: @test1
> +entry:
> +  %cmp1 = icmp ult float* %a, %a_end
> +  br i1 %cmp1, label %for.body.preheader, label %for.end
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b = load i64, i64* %b.i64, align 8
> +; CHECK: load float*, float**
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body, %for.body.preheader
> +  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +  %b.addr.02 = phi i64 [ %add.int, %for.body ], [ %b, %for.body.preheader ]
> +
> +; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +; CHECK: %b.addr.02.ptr = phi float* [ %add, %for.body ],
> +; CHECK-NOT: %b.addr.02 = phi i64
> +
> +  %tmp = inttoptr i64 %b.addr.02 to float*
> +; CHECK-NOT: inttoptr i64
> +  %tmp1 = load float, float* %tmp, align 4
> +  %mul.i = fmul float %tmp1, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %add = getelementptr inbounds float, float* %tmp, i64 1
> +  %add.int = ptrtoint float* %add to i64
> +; CHECK-NOT: ptrtoint float*
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
> +
> +define void @test1_neg(float* %a, float* readnone %a_end, i64* %b.i64) {
> +; CHECK-LABEL: @test1_neg
> +entry:
> +  %cmp1 = icmp ult float* %a, %a_end
> +  br i1 %cmp1, label %for.body.preheader, label %for.end
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b = load i64, i64* %b.i64, align 8
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body, %for.body.preheader
> +  %a.addr.03 = phi float* [ %incdec.ptr, %bb ], [ %a, %for.body.preheader ]
> +  %b.addr.02 = phi i64 [ %add.int, %bb ], [ %b, %for.body.preheader ]
> +
> +; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %bb ], [ %a, %for.body.preheader ]
> +; CHECK: %b.addr.02 = phi i64
> +
> +  %tmp = inttoptr i64 %b.addr.02 to float*
> +; CHECK: inttoptr i64
> +  %ptrcmp = icmp ult float* %tmp, %a_end
> +  br i1 %ptrcmp, label %for.end, label %bb
> +
> +bb:
> +  %tmp1 = load float, float* %a, align 4
> +  %mul.i = fmul float %tmp1, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %add = getelementptr inbounds float, float* %a, i64 1
> +  %add.int = ptrtoint float* %add to i64
> +; CHECK: ptrtoint float*
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
> +
> +
> +define void @test2(float* %a, float* readnone %a_end, float** %b.float) {
> +; CHECK-LABEL: @test2
> +entry:
> +  %cmp1 = icmp ult float* %a, %a_end
> +  br i1 %cmp1, label %for.body.preheader, label %for.end
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b.i64 = bitcast float** %b.float to i64*
> +  %b = load i64, i64* %b.i64, align 8
> +; CHECK: load float*, float**
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body, %for.body.preheader
> +  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +  %b.addr.02 = phi i64 [ %add.int, %for.body ], [ %b, %for.body.preheader ]
> +
> +; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +; CHECK: %b.addr.02.ptr = phi float* [ %add, %for.body ],
> +; CHECK-NOT: %b.addr.02 = phi i64
> +
> +  %tmp = inttoptr i64 %b.addr.02 to float*
> +; CHECK-NOT: inttoptr i64
> +  %tmp1 = load float, float* %tmp, align 4
> +  %mul.i = fmul float %tmp1, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %add = getelementptr inbounds float, float* %tmp, i64 1
> +  %add.int = ptrtoint float* %add to i64
> +; CHECK-NOT: ptrtoint float*
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
> +
> +
> +define void @test3(float* %a, float* readnone %a_end, i8** %b.i8p) {
> +; CHECK-LABEL: @test3
> +entry:
> +  %cmp1 = icmp ult float* %a, %a_end
> +  br i1 %cmp1, label %for.body.preheader, label %for.end
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b.i64 = bitcast i8** %b.i8p to i64*
> +  %b = load i64, i64* %b.i64, align 8
> +; CHECK: load float*, float**
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body, %for.body.preheader
> +  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +  %b.addr.02 = phi i64 [ %add.int, %for.body ], [ %b, %for.body.preheader ]
> +
> +; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +; CHECK: %b.addr.02.ptr = phi float* [ %add, %for.body ],
> +; CHECK-NOT: %b.addr.02 = phi i64
> +
> +  %tmp = inttoptr i64 %b.addr.02 to float*
> +; CHECK-NOT: inttoptr i64
> +  %tmp1 = load float, float* %tmp, align 4
> +  %mul.i = fmul float %tmp1, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %add = getelementptr inbounds float, float* %tmp, i64 1
> +  %add.int = ptrtoint float* %add to i64
> +; CHECK-NOT: ptrtoint float*
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
> +
> +
> +define void @test4(float* %a, float* readnone %a_end, float** %b.float) {
> +entry:
> +; CHECK-LABEL: @test4
> +  %cmp1 = icmp ult float* %a, %a_end
> +  br i1 %cmp1, label %for.body.preheader, label %for.end
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b.f = load float*, float** %b.float, align 8
> +  %b = ptrtoint float* %b.f to i64
> +; CHECK: load float*, float**
> +; CHECK-NOT: ptrtoint float*
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body, %for.body.preheader
> +  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +  %b.addr.02 = phi i64 [ %add.int, %for.body ], [ %b, %for.body.preheader ]
> +  %tmp = inttoptr i64 %b.addr.02 to float*
> +; CHECK-NOT: inttoptr i64
> +  %tmp1 = load float, float* %tmp, align 4
> +  %mul.i = fmul float %tmp1, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %add = getelementptr inbounds float, float* %tmp, i64 1
> +  %add.int = ptrtoint float* %add to i64
> +; CHECK-NOT: ptrtoint float*
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
>
> Added: llvm/trunk/test/Transforms/InstCombine/intptr2.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr2.ll?rev=314561&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/intptr2.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/intptr2.ll Fri Sep 29 15:10:15 2017
> @@ -0,0 +1,37 @@
> +; RUN: opt < %s  -instcombine -S | FileCheck %s
> +
> +define void @test1(float* %a, float* readnone %a_end, i32* %b.i) {
> +; CHECK-LABEL: @test1
> +entry:
> +  %cmp1 = icmp ult float* %a, %a_end
> +  br i1 %cmp1, label %for.body.preheader, label %for.end
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b = ptrtoint i32 * %b.i to i64
> +; CHECK: bitcast
> +; CHECK-NOT: ptrtoint
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body, %for.body.preheader
> +  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +  %b.addr.02 = phi i64 [ %add.int, %for.body ], [ %b, %for.body.preheader ]
> +
> +; CHECK:  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +; CHECK-NOT: phi i64
> +
> +  %tmp = inttoptr i64 %b.addr.02 to float*
> +; CHECK-NOT: inttoptr
> +  %tmp1 = load float, float* %tmp, align 4
> +  %mul.i = fmul float %tmp1, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %add = getelementptr inbounds float, float* %tmp, i64 1
> +  %add.int = ptrtoint float* %add to i64
> +; CHECK-NOT: ptrtoint
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
> +
>
> Added: llvm/trunk/test/Transforms/InstCombine/intptr3.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr3.ll?rev=314561&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/intptr3.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/intptr3.ll Fri Sep 29 15:10:15 2017
> @@ -0,0 +1,37 @@
> +; RUN: opt < %s  -instcombine -S | FileCheck %s
> +
> +
> +define  void @test(float* %a, float* readnone %a_end, i64 %b) unnamed_addr  {
> +entry:
> +  %cmp1 = icmp ult float* %a, %a_end
> +  br i1 %cmp1, label %for.body.preheader, label %for.end
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b.float = inttoptr i64 %b to float*
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body.preheader, %for.body
> +  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +  %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
> +  %b.addr.i64 = phi i64 [ %b.addr.i64.inc, %for.body ], [ %b, %for.body.preheader ]
> +; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +; CHECK-NEXT:  %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
> +; CHECK-NEXT: = load float
> +  %l = load float, float* %b.addr.float, align 4
> +  %mul.i = fmul float %l, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %b.addr.float.2 = inttoptr i64 %b.addr.i64 to float*
> +; CHECK-NOT: inttoptr
> +  %b.addr.float.inc = getelementptr inbounds float, float* %b.addr.float.2, i64 1
> +  %b.addr.i64.inc = ptrtoint float* %b.addr.float.inc to i64
> +; CHECK-NOT: ptrtoint
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
> +
> +
> +
>
> Added: llvm/trunk/test/Transforms/InstCombine/intptr4.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr4.ll?rev=314561&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/intptr4.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/intptr4.ll Fri Sep 29 15:10:15 2017
> @@ -0,0 +1,47 @@
> +; RUN: opt < %s  -instcombine -S | FileCheck %s
> +
> +
> +define  void @test(float* %a, float* readnone %a_end, i64 %b, float* %bf) unnamed_addr  {
> +entry:
> +  %cmp1 = icmp ult float* %a, %a_end
> +  %b.float = inttoptr i64 %b to float*
> +  br i1 %cmp1, label %bb1, label %bb2
> +
> +bb1:
> + br label %for.body.preheader
> +bb2:
> + %bfi = ptrtoint float* %bf to i64
> + br label %for.body.preheader
> +
> +for.body.preheader:                               ; preds = %entry
> +  %b.phi = phi i64 [%b, %bb1], [%bfi, %bb2]
> +; CHECK-LABEL: for.body.preheader
> +; CHECK-NOT: %b.phi = phi i64
> +  br label %for.body
> +
> +for.body:                                         ; preds = %for.body.preheader, %for.body
> +; CHECK-LABEL: for.body
> +  %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +  %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
> +  %b.addr.i64 = phi i64 [ %b.addr.i64.inc, %for.body ], [ %b.phi, %for.body.preheader ]
> +; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
> +; CHECK-NEXT:  %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
> +; CHECK-NOT: = %b.addr.i64
> +  %l = load float, float* %b.addr.float, align 4
> +  %mul.i = fmul float %l, 4.200000e+01
> +  store float %mul.i, float* %a.addr.03, align 4
> +  %b.addr.float.2 = inttoptr i64 %b.addr.i64 to float*
> +; CHECK-NOT: inttoptr
> +  %b.addr.float.inc = getelementptr inbounds float, float* %b.addr.float.2, i64 1
> +  %b.addr.i64.inc = ptrtoint float* %b.addr.float.inc to i64
> +; CHECK-NOT: ptrtoint
> +  %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
> +  %cmp = icmp ult float* %incdec.ptr, %a_end
> +  br i1 %cmp, label %for.body, label %for.end
> +
> +for.end:                                          ; preds = %for.body, %entry
> +  ret void
> +}
> +
> +
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list