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

Different iterator instructions reported in seemingly identical loops #1

Closed
robcasloz opened this issue May 29, 2019 · 5 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@robcasloz
Copy link

Hi Chris, thanks for the effort you put maintaining this library :)

In a simple single-loop function, the iterator recognition pass reports different LLVM IR instructions as belonging to the loop's iterator depending on whether the function returns:

void foo() {
  int i;
  for (i = 0; i < N; i++) {}
  return;
}

or exits:

void foo() {
  int i;
  for (i = 0; i < N; i++) {}
  exit(0);
}

The loops are identical in both cases, so I would expect the same instructions to be reported.

How to reproduce

  1. Run clang -emit-llvm -S foo.c -o foo.ll (foo.c is available here: foo.c.zip).
  2. Run opt -itr-annotate -S foo.ll -o foo-itr.ll.
  3. Assert that grep "iterator \!2" foo-itr.ll and grep "iterator \!3" foo-itr.ll produce the same output. Currently, this step fails.

Thank you for your time! Let me know if I can help in any way.

@compor
Copy link
Owner

compor commented May 30, 2019

Hey!

This is a quick response, but I'll look into it in depth later today.

So, without having a look at the attached files, I'd say that the IR generated is different because of exit(), which is known to terminate the program wherever/whenever it is called. In IR terms we'd get an unreachable terminator instruction. I'm not sure how that affects the analysis without a further look.

@compor compor added the bug Something isn't working label May 30, 2019
@compor compor self-assigned this May 30, 2019
@compor compor changed the title Different iterator instructions in seemingly equal loops Different iterator instructions reported in seemingly identical loops May 30, 2019
@compor
Copy link
Owner

compor commented May 30, 2019

A short update: It seems that the control dependence graph (CDG) generated for bar() (which uses exit()) is empty, which most likely means that the specific terminator instruction type (i.e. unreachable) is not handled.

@compor
Copy link
Owner

compor commented May 30, 2019

@robcasloz This was an issue with Pedigree, so I opened an issue for it here and it is hopefully address in the referenced PR.

Please try it and let me know.

@robcasloz
Copy link
Author

Hi @compor, I tried the PR and it works just fine, now the same instructions are reported as iterators in both cases. Thanks!

@compor
Copy link
Owner

compor commented May 31, 2019

Cool! I'm closing this since it was addressed here.
Thanks for catching this and all the feedback! 😄

@compor compor closed this as completed May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants