This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Compute AddRec range computations using different type BECount
ClosedPublic

Authored by caojoshua on May 30 2023, 1:59 AM.

Details

Summary

Before this patch, we can only use the MaxBECount for an AddRec's range
computation if the MaxBECount has <= bit width of the AddRec. This patch
reasons that if a MaxBECount has > bit width, and is <= the max value of
AddRec's bit width, we can still use the MaxBECount.

Diff Detail

Event Timeline

caojoshua created this revision.May 30 2023, 1:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 1:59 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
caojoshua updated this revision to Diff 526552.May 30 2023, 2:09 AM
caojoshua edited the summary of this revision. (Show Details)

Clean up code a bit

caojoshua published this revision for review.May 30 2023, 2:16 AM

I've no idea if the Dependence Analysis test change is correct. Would appreciate if reviews can look at it.

Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 2:16 AM
nikic requested changes to this revision.May 30 2023, 3:54 AM

Nice find! It looks like there are some polly tests that need updating.

llvm/lib/Analysis/ScalarEvolution.cpp
6710

static_cast -> cast

6712

.getActiveBits() <= BitWidth?

6723

It would probably make sense to convert this MaxBECount argument into an APInt (maybe as an NFC-refactoring before this change)?

This revision now requires changes to proceed.May 30 2023, 3:54 AM
caojoshua updated this revision to Diff 526891.May 30 2023, 9:32 PM
  • Rebase on top of a refactoring patch
  • Update polly tests. One test looks functionally the same, and the other test finds tighter bounds. Looks ok to me.
nikic accepted this revision.May 31 2023, 12:49 AM

LGTM

polly/test/CodeGen/switch-in-non-affine-region.ll
17–23

Don't match ; preds

This revision is now accepted and ready to land.May 31 2023, 12:49 AM
This revision was landed with ongoing or failed builds.May 31 2023, 9:32 PM
This revision was automatically updated to reflect the committed changes.

Hi,

The following starts failing with this patch:

opt -verify-scev -passes="loop(loop-unroll-full),loop-mssa(licm<allowspeculation>,indvars,loop-rotate)" bbi-83618.ll -o /dev/null

We get

Incorrect cached computation in ConstantMultipleCache for (-1 * (zext i16 {0,+,6}<nuw><%for.body> to i64))<nuw><nsw> : Computed -6 but cache contains -2!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: ../../main-github/llvm/build-all/bin/opt -verify-scev -passes=loop(loop-unroll-full),loop-mssa(licm<allowspeculation>,indvars,loop-rotate) bbi-83618.ll -o /dev/null
 #0 0x00005647691c5b77 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x2db3b77)
 #1 0x00005647691c389e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x2db189e)
 #2 0x00005647691c620f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f850faf2630 __restore_rt sigaction.c:0:0
 #4 0x00007f850d239387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f850d23aa78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00005647683ab616 llvm::ScalarEvolution::verify() const (../../main-github/llvm/build-all/bin/opt+0x1f99616)
 #7 0x0000564769cf7f36 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x38e5f36)
 #8 0x00005647693e0b5d llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x2fceb5d)
 #9 0x0000564768bd4ff4 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x27c2ff4)
#10 0x0000564767089c4d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0xc77c4d)
#11 0x0000564768bd93de llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x27c73de)
#12 0x00005647670899ed llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0xc779ed)
#13 0x0000564768bd4184 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x27c2184)
#14 0x0000564766cc4a1e llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (../../main-github/llvm/build-all/bin/opt+0x8b2a1e)
#15 0x0000564766cd30ee main (../../main-github/llvm/build-all/bin/opt+0x8c10ee)
#16 0x00007f850d225555 __libc_start_main (/lib64/libc.so.6+0x22555)
#17 0x0000564766cbf170 _start (../../main-github/llvm/build-all/bin/opt+0x8ad170)
Abort (core dumped)

Hi,

The following starts failing with this patch:

opt -verify-scev -passes="loop(loop-unroll-full),loop-mssa(licm<allowspeculation>,indvars,loop-rotate)" bbi-83618.ll -o /dev/null

I wrote https://github.com/llvm/llvm-project/issues/63385 about it.

Hi,

The following starts failing with this patch:

opt -verify-scev -passes="loop(loop-unroll-full),loop-mssa(licm<allowspeculation>,indvars,loop-rotate)" bbi-83618.ll -o /dev/null

I wrote https://github.com/llvm/llvm-project/issues/63385 about it.

Ping @caojoshua (or anyone else that understand what's going on)