Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScalarEvolution can't find iteration count without tail duplication #1473

Closed
llvmbot opened this issue Jan 10, 2007 · 4 comments
Closed

ScalarEvolution can't find iteration count without tail duplication #1473

llvmbot opened this issue Jan 10, 2007 · 4 comments
Labels
bugzilla Issues migrated from bugzilla code-quality

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 10, 2007

Bugzilla Link 1101
Resolution FIXED
Resolved on Feb 22, 2010 12:46
Version trunk
OS All
Attachments A simple loop without tail duplication., A simple loop with tail duplication.
Reporter LLVM Bugzilla Contributor

Extended Description

Hi, the TOT llvm can't find the iteration count without tail duplication, I
guess it's caused by the following code in

ScalaEvoluation.cpp:
// Currently we check for this by checking to see if the Exit branch goes to
// the loop header. If so, we know it will always execute the same number of
// times as the loop. More extensive analysis could be done to handle more
// cases here.
if (ExitBr->getSuccessor(0) != L->getHeader() &&
ExitBr->getSuccessor(1) != L->getHeader())
return UnknownValue;

I need to disable tail duplication because it changes a while loop to a do-
while loop by moving the exiting branch to the end of the loop body.

I attached two files: (1) foo.bc : a simple loop without tail duplication
(2) foo.taildup.bc: a simple loop with tail duplication. I ran "opt -indvar" on
these two files, llvm failed to find trip count on the first example; but if I
comment those three lines, it works fine and report the correct iteration
count. Based on my understanding, those checking are not necessary since
scalarevoluation works normally even the checking fails.

Thanks.

@lattner
Copy link
Collaborator

lattner commented Jan 14, 2007

This makes sense. The tail duplication pass does "loop rotation". This moves the exit condition from
the top of the loop to the end of the loop, duplicating it so that the loop is not entered if the condition
is false for the first iteration. For example:

Before:

Loop:
if !condition goto Out
loop body
goto Loop
Out:

After:

if !condition goto Out
Loop:
loop body
if condition goto Loop
Out:

without this transformation, it is significantly harder to determine the trip count of the loop.

@lattner
Copy link
Collaborator

lattner commented Jan 14, 2007

Also, specifically answering your question, it's not safe to disable those checks. Doing so makes the trip
count be miscomputed for the case in bug 1015. Basically, we have to be sure the exit condition will be
executed each time through the loop.

In this specific case, it would also be safe to check to see if the loop exit block is the loop header. I'll
investigate whether that fixes the issue in this case.

@lattner
Copy link
Collaborator

lattner commented Jan 14, 2007

urg, due to recent bytecode format changes, I can't read your .bc files. Can you please attach a .ll file for
the not tail duplicated case?

Thanks,

-Chris

@lattner
Copy link
Collaborator

lattner commented Jan 14, 2007

I figured out my own testcase. Testcase here:
Analysis/ScalarEvolution/trip-count.ll

Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070108/042645.html

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
clementval pushed a commit to clementval/llvm-project that referenced this issue Feb 16, 2022
* [flang][driver] Extend support for LLVM IR/BC files

Before this change, `clangDriver` (i.e. the compiles driver library)
would always use `clang` to compile LLVM IR or LLVM BC files (even when
`flang-new` was used to invoke the driver). With this change, Flang will
finally accept LLVM IR and LLVM BC alongside e.g. Fortran input files.
This means that from now on it is up to the user to decide whether to
use Flang or Clang to compile an LLVM file (`flang-new -c file.bc` and
`clang -c file.bc`, respectively).

To complement this, support for generating LLVM BC files is added. This
requires the `BitcodeWriterPass` pass to be run on the input LLVM IR
module and is implemented as a dedicated frontend aciton.

The new functionality as seen by the user:
1. LLVM BC file generation (`flang-new -c -emit-llvm file.90` or
   `flang-new -fc1 -emit-llvm-bc file.f90`)
2. Ability to consume LLVM IR and BC files and to lower them to object
   files (`flang-new -c file.bc` or `flang-new -c file.ll`)

The new behaviour is consistent with `clang` and `clang -cc1`.

* [flang][driver] Add support for `-save-temps`

This patch adds support for `-save-temps` in `flang-new`, Flang's
compiler driver. The semantics of this option are inherited from Clang.

The file extension for temporary Fortran preprocessed files is set to
`i`. This is identical to what Clang uses for C (or C++) preprocessed
files. I have tried researching what other compilers do here, but I
couldn't find any definitive answers. One GFortran thread [1] suggests
that indeed it is not clear what the right approach should be.

As `-save-temps` makes the compiler run every phase separately, in Flang
one currently has to use it with `-fno-integrated-as`. Otherwise, an
invocation to the integrated assembler driver is generated (i.e.
something equivalent to `clang -cc1as` from Clang), but this is not yet
implemented in Flang.

[1] https://gcc.gnu.org/bugzilla//show_bug.cgi?id=81615

* Add missing llvm-dis dependency

* Add MacOSX to the list of supported OSes

The PR for this branch was reverted due to failures in our MacOS CI. I'm
enabling support for MacOS to verify that this is sufficient for the
tests to pass.

* Simplify test
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla code-quality
Projects
None yet
Development

No branches or pull requests

2 participants