Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:45:21+00:00 2026-06-02T04:45:21+00:00

It is easy to see that: (i % 3 == 0) && (i %

  • 0

It is easy to see that:

(i % 3 == 0) && (i % 5 == 0)

Can be simplified to:

(i % 15 == 0)

Yet looking into the output of GCC, it seems this is not done even at high optimisation levels.

Do any compilers do these sorts of optimisations, or is there a good reason why those two tests are not semantically equivalent?

Edit: In response to those who say this is a fringe case, the following is a similar case:

(i < 3) && (i < 5)

Any number less than 3, must always be less than 5. Second test is redundant.

I would also like to add the following in response to the answer that the compiler cannot know if the environment is affected… Look at this code:

void foo(void)
{
    int i;
    for (i = 0; i <= 10; i++)
    {
        if (i > 20)
        {
            puts("Hi");
        }
    }
}

Whole function is reduced to “repz ret” by GCC with -O2. That is far more complex than anything I am talking about.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:45:22+00:00Added an answer on June 2, 2026 at 4:45 am

    Ignore all the silly answers claiming this is terribly difficult/impossible for a compiler to do. I see no reason why it would be difficult, but presumably either nobody thought of doing it or thought it would be sufficiently important to optimize. If you want a better answer than this you’ll need to report it on the GCC bug tracker as a request for enhancement and see what the developers say.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking at Gmail's cookies it's easy to see what's stored in the remember me
What's an easy way to see the trace() output of Flash/Flex movies when running
An easy problem, but for some reason I just can't figure this out today.
I can see this question (or a similar one) has been asked a few
can anyone please explain how this works (asz + 7) & ~7; It rounds
I am looking to see how a function that computes the Hessian of a
I'm trying to use this thumbnail generator, but as you can see you have
Is there a an easy way to see(timestamp) when a database was last altered
Is there an easy way to see the actual SQL generated by a rails
Flat-file JMS authentication is easy to set up on Glassfish (see http://docs.sun.com/app/docs/doc/821-0027/aeofg?a=view ). The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.