This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Make SCEV or modeling more aggressive.
Changes PlannedPublic

Authored by efriedma on Apr 19 2017, 12:30 PM.

Details

Summary

Use haveNoCommonBitsSet to figure out whether an "or" instruction is equivalent to addition. This handles more cases than just checking for a constant on the RHS.

Diff Detail

Event Timeline

efriedma created this revision.Apr 19 2017, 12:30 PM
sanjoy accepted this revision.Apr 19 2017, 12:55 PM

lgtm!

This revision is now accepted and ready to land.Apr 19 2017, 12:55 PM
This revision was automatically updated to reflect the committed changes.

this patch introduces infinite loop when compiling pyrite kernel[0] for r600 (turks) target:

Thread 1 "cl-program-test" received signal SIGSEGV, Segmentation fault.
0x00007fffdba03e36 in llvm::DenseMapBase<llvm::DenseMap<llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u>, llvm::DenseMapInfo<llvm::Value*>, llvm::detail::DenseMapPair<llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u> > >, llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u>, llvm::DenseMapInfo<llvm::Value*>, llvm::detail::DenseMapPair<llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u> > >::find_as<llvm::Value*> (
    this=0x8b09b0, Val=@0x7fffff7ff068: 0xe83e50)
    at /home/vesely/llvm/include/llvm/ADT/DenseMap.h:151
151	    if (LookupBucketFor(Val, TheBucket))
(gdb) bt
#0  0x00007fffdba03e36 in llvm::DenseMapBase<llvm::DenseMap<llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u>, llvm::DenseMapInfo<llvm::Value*>, llvm::detail::DenseMapPair<llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u> > >, llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u>, llvm::DenseMapInfo<llvm::Value*>, llvm::detail::DenseMapPair<llvm::AssumptionCache::AffectedValueCallbackVH, llvm::SmallVector<llvm::WeakVH, 1u> > >::find_as<llvm::Value*> (
    this=0x8b09b0, Val=@0x7fffff7ff068: 0xe83e50)
    at /home/vesely/llvm/include/llvm/ADT/DenseMap.h:151
#1  0x00007fffdbb8195c in llvm::AssumptionCache::assumptionsFor (
    this=0x8b0930, V=0xe83e50)
    at /home/vesely/llvm/include/llvm/Analysis/AssumptionCache.h:134
#2  0x00007fffdbd3274c in computeKnownBitsFromAssume (V=0xe83e50, 
    KnownZero=..., KnownOne=..., Depth=5, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:515
#3  0x00007fffdbd3944f in computeKnownBits (V=0xe83e50, KnownZero=..., 
    KnownOne=..., Depth=5, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1601
#4  0x00007fffdbd314c1 in computeKnownBitsAddSub (Add=true, Op0=0xe83e50, 
    Op1=0x8f5540, NSW=false, KnownZero=..., KnownOne=..., KnownZero2=..., 
    KnownOne2=..., Depth=4, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:263
#5  0x00007fffdbd372ff in computeKnownBitsFromOperator (I=0xe83f00, 
---Type <return> to continue, or q <return> to quit---
    KnownZero=..., KnownOne=..., Depth=4, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1160
#6  0x00007fffdbd393c0 in computeKnownBits (V=0xe83f00, KnownZero=..., 
    KnownOne=..., Depth=4, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1588
#7  0x00007fffdbd314c1 in computeKnownBitsAddSub (Add=true, Op0=0xe83f00, 
    Op1=0xe81b00, NSW=false, KnownZero=..., KnownOne=..., KnownZero2=..., 
    KnownOne2=..., Depth=3, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:263
#8  0x00007fffdbd372ff in computeKnownBitsFromOperator (I=0xe83fb0, 
    KnownZero=..., KnownOne=..., Depth=3, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1160
#9  0x00007fffdbd393c0 in computeKnownBits (V=0xe83fb0, KnownZero=..., 
    KnownOne=..., Depth=3, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1588
#10 0x00007fffdbd314c1 in computeKnownBitsAddSub (Add=true, Op0=0xe83fb0, 
    Op1=0xe83a60, NSW=false, KnownZero=..., KnownOne=..., KnownZero2=..., 
    KnownOne2=..., Depth=2, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:263
#11 0x00007fffdbd372ff in computeKnownBitsFromOperator (I=0xe84060, 
    KnownZero=..., KnownOne=..., Depth=2, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1160
#12 0x00007fffdbd393c0 in computeKnownBits (V=0xe84060, KnownZero=..., 
---Type <return> to continue, or q <return> to quit---
    KnownOne=..., Depth=2, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1588
#13 0x00007fffdbd314c1 in computeKnownBitsAddSub (Add=true, Op0=0xe84060, 
    Op1=0xe837d0, NSW=false, KnownZero=..., KnownOne=..., KnownZero2=..., 
    KnownOne2=..., Depth=1, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:263
#14 0x00007fffdbd372ff in computeKnownBitsFromOperator (I=0xe84110, 
    KnownZero=..., KnownOne=..., Depth=1, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1160
#15 0x00007fffdbd393c0 in computeKnownBits (V=0xe84110, KnownZero=..., 
    KnownOne=..., Depth=1, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1588
#16 0x00007fffdbd356ea in computeKnownBitsFromShiftOperator(const llvm::Operator *, llvm::APInt &, llvm::APInt &, llvm::APInt &, llvm::APInt &, unsigned int, const (anonymous namespace)::Query &, llvm::function_ref<llvm::APInt(const llvm::APInt&, unsigned int)>, llvm::function_ref<llvm::APInt(const llvm::APInt&, unsigned int)>) (I=0xe843d0, KnownZero=..., KnownOne=..., KnownZero2=..., 
    KnownOne2=..., Depth=0, Q=..., KZF=..., KOF=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:813
#17 0x00007fffdbd37088 in computeKnownBitsFromOperator (I=0xe843d0, 
    KnownZero=..., KnownOne=..., Depth=0, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1113
#18 0x00007fffdbd393c0 in computeKnownBits (V=0xe843d0, KnownZero=..., 
---Type <return> to continue, or q <return> to quit---
    KnownOne=..., Depth=0, Q=...)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:1588
#19 0x00007fffdbd30d34 in llvm::computeKnownBits (V=0xe843d0, KnownZero=..., 
    KnownOne=..., DL=..., Depth=0, AC=0x8b0930, CxtI=0x0, DT=0x89fb80, ORE=0x0)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:142


#20 0x00007fffdbd30ee1 in llvm::haveNoCommonBitsSet (LHS=0xe843d0, 
    RHS=0xe84480, DL=..., AC=0x8b0930, CxtI=0x0, DT=0x89fb80)
    at /home/vesely/llvm/lib/Analysis/ValueTracking.cpp:156
#21 0x00007fffdbc9a13e in llvm::ScalarEvolution::createSCEV (this=0x88c980, 
    V=0xe84530) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:5332
#22 0x00007fffdbc913f8 in llvm::ScalarEvolution::getSCEV (this=0x88c980, 
    V=0xe84530) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:3574
...
#9170 0x00007fffdbc913f8 in llvm::ScalarEvolution::getSCEV (this=0x88c980, 
    V=0xb45b70) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:3574
#9171 0x00007fffdbc9a175 in llvm::ScalarEvolution::createSCEV (this=0x88c980, 
    V=0xb45c20) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:5336
#9172 0x00007fffdbc913f8 in llvm::ScalarEvolution::getSCEV (this=0x88c980, 
    V=0xb45c20) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:3574
#9173 0x00007fffdbc9925f in llvm::ScalarEvolution::createSCEV (this=0x88c980, 
    V=0xb45f50) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:5213
#9174 0x00007fffdbc913f8 in llvm::ScalarEvolution::getSCEV (this=0x88c980, 
    V=0xb45f50) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:3574
#9175 0x00007fffdbc99862 in llvm::ScalarEvolution::createSCEV (this=0x88c980, 
    V=0xb46290) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:5271
#9176 0x00007fffdbc913f8 in llvm::ScalarEvolution::getSCEV (this=0x88c980, 
    V=0xb46290) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:3574
#9177 0x00007fffdbc9a175 in llvm::ScalarEvolution::createSCEV (this=0x88c980, 
    V=0xb46340) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:5336
#9178 0x00007fffdbc913f8 in llvm::ScalarEvolution::getSCEV (this=0x88c980, 
    V=0xb46340) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:3574
#9179 0x00007fffdbc9925f in llvm::ScalarEvolution::createSCEV (this=0x88c980, 
    V=0xb46670) at /home/vesely/llvm/lib/Analysis/ScalarEvolution.cpp:5213

[0] https://cgit.freedesktop.org/piglit/tree/tests/cl/program/execute/pyrit-wpa-psk.cl

revision r300742 works OK. so does reverting this change on top of r300918

Reverted in r300928.

@jvesely, could you file a bug at bugs.llvm.org with a testcase for that crash? (Please include preprocessed source and command-line to reproduce.)

efriedma reopened this revision.Apr 20 2017, 5:15 PM
This revision is now accepted and ready to land.Apr 20 2017, 5:15 PM

@jvesely, could you file a bug at bugs.llvm.org with a testcase for that crash? (Please include preprocessed source and command-line to reproduce.)

http://bugs.llvm.org/show_bug.cgi?id=32731

efriedma planned changes to this revision.Aug 3 2018, 2:52 PM

getSCEV is still recurses without a limit, so this still blows out the stack, and gets very slow for complex expressions.

This revision was not accepted when it landed; it landed in state Changes Planned.Oct 7 2019, 6:13 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 7 2019, 6:14 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
efriedma reopened this revision.Oct 7 2019, 12:21 PM

This was reverted.

This revision is now accepted and ready to land.Oct 7 2019, 12:21 PM
efriedma planned changes to this revision.Oct 7 2019, 12:21 PM
sanjoy resigned from this revision.Jan 29 2022, 5:28 PM