[PATCH] D33110: [CodeGenPrepare] Don't create inttoptr for ni ptrs

Yichao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 17 15:12:40 PDT 2017


yuyichao added a comment.

I'm seeing a similar failure caused by the same code even with this patch applied on LLVM 4.0.

The relevant IR is

  %32 = call %jl_value_t addrspace(10)* %31(i64 %24), !dbg !22697
  %34 = addrspacecast %jl_value_t addrspace(10)* %32 to %jl_value_t*
  %35 = ptrtoint %jl_value_t* %34 to i64, !dbg !22699
  %36 = add i64 %35, 8, !dbg !22699
  %76 = inttoptr i64 %36 to i8*
  %77 = getelementptr i8, i8* %76, i64 2, !dbg !22717

And when it enters the `else` branch around L4368 `Addr` is `%77 = getelementptr i8, i8* %76, i64 2, !dbg !22717` and `AddrMode.BaseReg` is `%32 = call %jl_value_t addrspace(10)* %31(i64 %24), !dbg !22697`. This is not handled by the non-integral pointer check added in the PR and causes a `ptrtoint` on `%32`. The following patch <https://github.com/JuliaLang/julia/blob/f5912c1ae308e2308a4a384547dc1fd0892edb6f/deps/patches/llvm-Yet-another-fix.patch> seems to fix it

  diff
  diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp
  index 44d6b3e264c..4177819e989 100644
  --- a/lib/CodeGen/CodeGenPrepare.cpp
  +++ b/lib/CodeGen/CodeGenPrepare.cpp
  @@ -4067,6 +4067,23 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
       // non-integral pointers, so in that case bail out now.
       if (DL->isNonIntegralPointerType(Addr->getType()))
         return false;
  +    if (AddrMode.BaseReg) {
  +      Type *BaseTy = AddrMode.BaseReg->getType();
  +      if (BaseTy->isPointerTy() && DL->isNonIntegralPointerType(BaseTy)) {
  +        return false;
  +      }
  +    }
  +    if (AddrMode.Scale) {
  +      Type *ScaleTy = AddrMode.ScaledReg->getType();
  +      if (ScaleTy->isPointerTy() && DL->isNonIntegralPointerType(ScaleTy)) {
  +        return false;
  +      }
  +    }
  +    if (AddrMode.BaseGV) {
  +      if (DL->isNonIntegralPointerType(AddrMode.BaseGV->getType())) {
  +        return false;
  +      }
  +    }
   
       DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode << " for "
                    << *MemoryInst << "\n");

Not sure if it is the right fix.


https://reviews.llvm.org/D33110





More information about the llvm-commits mailing list