[llvm-bugs] [Bug 34627] New: InstCombine fails when constant folding gep with vector result: Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"'

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 15 08:45:47 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34627

            Bug ID: 34627
           Summary: InstCombine fails when constant folding gep with
                    vector result: Assertion `New->getType() == getType()
                    && "replaceAllUses of value with new value of
                    different type!"'
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: mattias.v.eriksson at ericsson.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 19163
  --> https://bugs.llvm.org/attachment.cgi?id=19163&action=edit
Bugpointed reproducer

This fails for me on trunk:

opt -instcombine  -S -o /dev/null ic.ll -debug

INSTCOMBINE ITERATION #1 on foo
IC: ConstFold to: <2 x i16> <i16 0, i16 undef> from:   %broadcast.splatinsert =
insertelement <2 x i16> undef, i16 0, i32 0
IC: ConstFold to: <2 x i16> zeroinitializer from:   %broadcast.splat =
shufflevector <2 x i16> <i16 0, i16 undef>, <2 x i16> undef, <2 x i32>
zeroinitializer
IC: DCE:   %induction = add <2 x i16> zeroinitializer, <i16 0, i16 1>
IC: ConstFold to: <2 x i16> undef from:   %0 = insertelement <2 x i16> undef,
i16 undef, i32 0
IC: ConstFold to: <2 x i16> undef from:   %0 = insertelement <2 x i16> undef,
i16 undef, i32 1
IC: ConstFold to: %stc2* null from:   %0 = getelementptr inbounds [10 x %stc2],
[10 x %stc2]* null, i16 0, <2 x i16> undef

[Note that the last argument to this getelementptr is a vector.]

opt: /home/qmaseon/git/llvm/lib/IR/Value.cpp:402: void
llvm::Value::doRAUW(llvm::Value *, bool): Assertion `New->getType() ==
getType() && "replaceAllUses of value with new value of different type!"'
failed.
#0 0x00000000031a8f6c llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/qmaseon/git/llvm/lib/Support/Unix/Signals.inc:398:13
#1 0x00000000031a9119 PrintStackTraceSignalHandler(void*)
/home/qmaseon/git/llvm/lib/Support/Unix/Signals.inc:462:1
#2 0x00000000031a7603 llvm::sys::RunSignalHandlers()
/home/qmaseon/git/llvm/lib/Support/Signals.cpp:50:5
#3 0x00000000031a97af SignalHandler(int)
/home/qmaseon/git/llvm/lib/Support/Unix/Signals.inc:252:1
#4 0x00007f89af0b8330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#5 0x00007f89adca7c37 gsignal
/build/eglibc-SvCtMH/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#6 0x00007f89adcab028 abort
/build/eglibc-SvCtMH/eglibc-2.19/stdlib/abort.c:91:0
#7 0x00007f89adca0bf6 __assert_fail_base
/build/eglibc-SvCtMH/eglibc-2.19/assert/assert.c:92:0
#8 0x00007f89adca0ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#9 0x00000000029fac31 llvm::Value::doRAUW(llvm::Value*, bool)
/home/qmaseon/git/llvm/lib/IR/Value.cpp:405:7
#10 0x00000000029fb222 llvm::Value::replaceAllUsesWith(llvm::Value*)
/home/qmaseon/git/llvm/lib/IR/Value.cpp:430:1
#11 0x0000000002b96316 AddReachableCodeToWorklist(llvm::BasicBlock*,
llvm::DataLayout const&, llvm::SmallPtrSetImpl<llvm::BasicBlock*>&,
llvm::InstCombineWorklist&, llvm::TargetLibraryInfo const*)
/home/qmaseon/git/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3098:11
#12 0x0000000002b95ed3 prepareICWorklistFromFunction(llvm::Function&,
llvm::DataLayout const&, llvm::TargetLibraryInfo*, llvm::InstCombineWorklist&)
/home/qmaseon/git/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3179:7
#13 0x0000000002b9577d combineInstructionsOverFunction(llvm::Function&,
llvm::InstCombineWorklist&, llvm::AAResults*, llvm::AssumptionCache&,
llvm::TargetLibraryInfo&, llvm::DominatorTree&,
llvm::OptimizationRemarkEmitter&, bool, llvm::LoopInfo*)
/home/qmaseon/git/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3229:21
#14 0x0000000002b95ad1
llvm::InstructionCombiningPass::runOnFunction(llvm::Function&)
/home/qmaseon/git/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3293:10
#15 0x0000000002971210 llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/qmaseon/git/llvm/lib/IR/LegacyPassManager.cpp:1514:23
#16 0x0000000002971545 llvm::FPPassManager::runOnModule(llvm::Module&)
/home/qmaseon/git/llvm/lib/IR/LegacyPassManager.cpp:1535:16
#17 0x0000000002971d31 (anonymous
namespace)::MPPassManager::runOnModule(llvm::Module&)
/home/qmaseon/git/llvm/lib/IR/LegacyPassManager.cpp:1591:23
#18 0x000000000297182b llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/qmaseon/git/llvm/lib/IR/LegacyPassManager.cpp:1694:16
#19 0x0000000002972271 llvm::legacy::PassManager::run(llvm::Module&)
/home/qmaseon/git/llvm/lib/IR/LegacyPassManager.cpp:1725:10
#20 0x0000000000b5ea4d main /home/qmaseon/git/llvm/tools/opt/opt.cpp:757:3
#21 0x00007f89adc92f45 __libc_start_main
/build/eglibc-SvCtMH/eglibc-2.19/csu/libc-start.c:321:0
#22 0x0000000000b32dc9 _start (/mnt/tb/builds/build-master/bin/opt+0xb32dc9)

I think the bug is in the function ConstantFoldGetElementPtr:
    if (isNull) {
      PointerType *PtrTy = cast<PointerType>(C->getType()->getScalarType());
      Type *Ty = GetElementPtrInst::getIndexedType(PointeeTy, Idxs);

      assert(Ty && "Invalid indices for GEP!");
      Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
      if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
        GEPTy = VectorType::get(GEPTy, VT->getNumElements());

      // I think for this case we should return a NullValue of VectorType.

      return Constant::getNullValue(GEPTy);
    }
  }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170915/d65bdb81/attachment-0001.html>


More information about the llvm-bugs mailing list