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

Is there a pass to solve the following dead code? #730

Closed
fa1conn opened this issue Oct 21, 2022 · 7 comments
Closed

Is there a pass to solve the following dead code? #730

fa1conn opened this issue Oct 21, 2022 · 7 comments

Comments

@fa1conn
Copy link

fa1conn commented Oct 21, 2022

for example

      if (Integer.parseInt("0") != 0) {
          i8 = 0;
          i7 = 0;
          columnName = null;
      } else {
          i7 = 28;
          i8 = 93;
      }
@ssj933
Copy link
Contributor

ssj933 commented Oct 21, 2022

We don't have a pass currently do this. Seems like something that can be added to constant propagation.

@NTillmann
Copy link
Contributor

This commit can serve as a template for how you could plug logic for Integer.parseInt: 25593e1

@fa1conn
Copy link
Author

fa1conn commented Oct 30, 2022

This commit can serve as a template for how you could plug logic for Integer.parseInt: 25593e1

Thanks,I used newest redex to test the String.equals by using ConstantPropagationPass, but it doesn't work. How to make it work?

@fa1conn
Copy link
Author

fa1conn commented Oct 31, 2022

This commit can serve as a template for how you could plug logic for Integer.parseInt: 25593e1

For Boolean.valueOf, It is Effective by using CommonSubexpressionEliminationPass.
For String.equals, It maybe Effective by using peepholePass. It depond on bytecode order matching. If there is some bytecode that interferes with the order it will not be recognized.
And I used ConstantPropagationPass, I found it It doesn't call StringAnalyzer::analyze_invoke function. Does it require additional configuration, or what conditions need to be met to trigger it?

@NTillmann
Copy link
Contributor

ConstantPropagationPass, but it doesn't work

Right, good observation. The ConstantPropagationPass only uses the PrimitiveAnalyzer by default. Other more sophisticated passes use multiple analyzers include the StringAnalyzer, e.g. the InterproceduralConstantPropagationPass, and ShrinkerPass (which basically runs several local optimizations concurrently, which is faster than running individual local optimizations sequentially), and many other passes that (can) use shrinking as part of their operations, e.g. the MethodInlinePass, the IntraDexInlinePass.

I'll look into upgrading ConstantPropagationPass and will report back on that.

@NTillmann
Copy link
Contributor

This would upgrade ConstantPropagationPass to also use the StringAnalyzer (and various other analyzers): #733

However, by itself, it doesn't seem to add much value, just makes the build a bit slower, and by changing some local decisions it may regress the final size a bit. So I am not planning on merging that right now. But you could use it locally if it helps you.

@fa1conn
Copy link
Author

fa1conn commented Nov 4, 2022

This would upgrade ConstantPropagationPass to also use the StringAnalyzer (and various other analyzers): #733

However, by itself, it doesn't seem to add much value, just makes the build a bit slower, and by changing some local decisions it may regress the final size a bit. So I am not planning on merging that right now. But you could use it locally if it helps you.

Thank you very much!

@fa1conn fa1conn closed this as completed Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants