[llvm-bugs] [Bug 37936] New: 'Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.' with -indvars -loop-instsimplify -loop-reduce

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 26 01:16:11 PDT 2018


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

            Bug ID: 37936
           Summary: 'Assertion `isa<X>(Val) && "cast<Ty>() argument of
                    incompatible type!"' failed.' with -indvars
                    -loop-instsimplify -loop-reduce
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: mikael.holmen at ericsson.com
                CC: llvm-bugs at lists.llvm.org

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

Running 

 opt -S -o - bbi-15634.ll -indvars -loop-instsimplify -loop-reduce

crashes with

opt: ../include/llvm/Support/Casting.h:255: typename cast_retty<X, Y
*>::ret_type llvm::cast(Y *) [X = llvm::Instruction, Y = llvm::Value]:
Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Stack dump:
0.      Program arguments: /data/repo/llvm-patch/build-all/bin/opt -S -o -
bbi-15634.ll -indvars -verify -loop-instsimplify -verify -loop-reduce 
1.      Running pass 'Function Pass Manager' on module 'bbi-15634.ll'.
2.      Running pass 'Loop Pass Manager' on function '@f1'
3.      Running pass 'Loop Strength Reduction' on basic block '%for.cond'
#0 0x0000000001ff4ac4 PrintStackTraceSignalHandler(void*)
(/data/repo/llvm-patch/build-all/bin/opt+0x1ff4ac4)
#1 0x0000000001ff2d30 llvm::sys::RunSignalHandlers()
(/data/repo/llvm-patch/build-all/bin/opt+0x1ff2d30)
#2 0x0000000001ff4e28 SignalHandler(int)
(/data/repo/llvm-patch/build-all/bin/opt+0x1ff4e28)
#3 0x00007f1a4d86f330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#4 0x00007f1a4c45ec37 gsignal
/build/eglibc-ripdx6/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007f1a4c462028 abort
/build/eglibc-ripdx6/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007f1a4c457bf6 __assert_fail_base
/build/eglibc-ripdx6/eglibc-2.19/assert/assert.c:92:0
#7 0x00007f1a4c457ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#8 0x00000000015e6b71
llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*,
llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&, bool&)
(/data/repo/llvm-patch/build-all/bin/opt+0x15e6b71)
#9 0x00000000015e7237
llvm::SCEVExpander::expandAddRecExprLiterally(llvm::SCEVAddRecExpr const*)
(/data/repo/llvm-patch/build-all/bin/opt+0x15e7237)
#10 0x00000000015e2ce3 llvm::SCEVExpander::expand(llvm::SCEV const*)
(/data/repo/llvm-patch/build-all/bin/opt+0x15e2ce3)
#11 0x00000000015e22d9 llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*,
llvm::Type*) (/data/repo/llvm-patch/build-all/bin/opt+0x15e22d9)
#12 0x0000000001e69f87 (anonymous namespace)::LSRInstance::Expand((anonymous
namespace)::LSRUse const&, (anonymous namespace)::LSRFixup const&, (anonymous
namespace)::Formula const&,
llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true,
false, void>, false, false>, llvm::SCEVExpander&,
llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) const
(/data/repo/llvm-patch/build-all/bin/opt+0x1e69f87)
#13 0x0000000001e5b98e (anonymous
namespace)::LSRInstance::LSRInstance(llvm::Loop*, llvm::IVUsers&,
llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&,
llvm::TargetTransformInfo const&)
(/data/repo/llvm-patch/build-all/bin/opt+0x1e5b98e)
#14 0x0000000001e545fa ReduceLoopStrength(llvm::Loop*, llvm::IVUsers&,
llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&,
llvm::TargetTransformInfo const&)
(/data/repo/llvm-patch/build-all/bin/opt+0x1e545fa)
#15 0x0000000001e5514f (anonymous
namespace)::LoopStrengthReduce::runOnLoop(llvm::Loop*, llvm::LPPassManager&)
(/data/repo/llvm-patch/build-all/bin/opt+0x1e5514f)
#16 0x00000000015301e5 llvm::LPPassManager::runOnFunction(llvm::Function&)
(/data/repo/llvm-patch/build-all/bin/opt+0x15301e5)
#17 0x0000000001a7c2ba llvm::FPPassManager::runOnFunction(llvm::Function&)
(/data/repo/llvm-patch/build-all/bin/opt+0x1a7c2ba)
#18 0x0000000001a7c518 llvm::FPPassManager::runOnModule(llvm::Module&)
(/data/repo/llvm-patch/build-all/bin/opt+0x1a7c518)
#19 0x0000000001a7ca4d llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/data/repo/llvm-patch/build-all/bin/opt+0x1a7ca4d)
#20 0x0000000000745e8c main (/data/repo/llvm-patch/build-all/bin/opt+0x745e8c)
#21 0x00007f1a4c449f45 __libc_start_main
/build/eglibc-ripdx6/eglibc-2.19/csu/libc-start.c:321:0
#22 0x000000000072f1ed _start
(/data/repo/llvm-patch/build-all/bin/opt+0x72f1ed)
Abort



It starts crashing with r334298:

    [InstSimplify] add nuw %x, -1 -> -1 fold.

    Summary:
    `%ret = add nuw i8 %x, C`
    From [[ https://llvm.org/docs/LangRef.html#add-instruction | langref ]]:
        nuw and nsw stand for “No Unsigned Wrap” and “No Signed Wrap”,
        respectively. If the nuw and/or nsw keywords are present,
        the result value of the add is a poison value if unsigned
        and/or signed overflow, respectively, occurs.

    So if `C` is `-1`, `%x` can only be `0`, and the result is always `-1`.

    I'm not sure we want to use `KnownBits`/`LVI` here, because there is
    exactly one possible value (all bits set, `-1`), so some other pass
    should take care of replacing the known-all-ones with constant `-1`.

    The `test/Transforms/InstCombine/set-lowbits-mask-canonicalize.ll` change
*is* confusing.
    What happening is, before this: (omitting `nuw` for simplicity)
    1. First, InstCombine D47428/rL334127 folds `shl i32 1, %NBits`) to `shl
nuw i32 -1, %NBits`
    2. Then, InstSimplify D47883/rL334222 folds `shl nuw i32 -1, %NBits` to
`-1`,
    3. `-1` is inverted to `0`.
    But now:
    1. *This* InstSimplify fold `%ret = add nuw i32 %setbit, -1` -> `-1`
happens first,
       before InstCombine D47428/rL334127 fold could happen.
    Thus we now end up with the opposite constant,
    and it is all good: https://rise4fun.com/Alive/OA9

    https://rise4fun.com/Alive/sldC
    Was mentioned in D47428 review.
    Follow-up for D47883.

    Reviewers: spatel, craig.topper

    Reviewed By: spatel

    Subscribers: llvm-commits

    Differential Revision: https://reviews.llvm.org/D47908

    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334298
91177308-0d34-0410-b5e6-96231b3b80d8


Found this when fuzz testing with random passes on random input.

-- 
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/20180626/107a6481/attachment-0001.html>


More information about the llvm-bugs mailing list