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 7514631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:33:21+00:00 2026-05-30T00:33:21+00:00

%4 = icmp sgt i32 %2, %3 For the above instruction, how can I

  • 0
 %4 = icmp sgt i32 %2, %3

For the above instruction, how can I check whether the icmp instruction contains sgt or slt?

  • 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-05-30T00:33:23+00:00Added an answer on May 30, 2026 at 12:33 am

    A direct answer to your question is to place this code in a custom FunctionPass:

    virtual bool runOnFunction(Function &F) {
        for (Function::iterator bb = F.begin(), bb_e = F.end(); bb != bb_e; ++bb) {
            for (BasicBlock::iterator ii = bb->begin(), ii_e = bb->end(); ii != ii_e; ++ii) {
                if (CmpInst *cmpInst = dyn_cast<CmpInst>(&*ii)) {
                    handle_cmp(cmpInst);
                }
            }
        }
        return false;
    }
    
    void handle_cmp(CmpInst *cmpInst) {
        if (cmpInst->getPredicate() == CmpInst::ICMP_SGT) {
            errs() << "In the following instruction, SGT predicate\n";
            cmpInst->dump();
        }
    }
    

    You seem to be asking a lot of similar questions lately, so I want to give a more general piece of advice.

    Each instruction you see in LLVM IR is just a textual representation of an instruction class that exists in the LLVM code base. In this case icmp represents ICmpInst, which is a subclass of CmpInst. Once you know you’re dealing with CmpInst, it’s easy to see how to access its attributes just by reading the class declaration in the header file. For instance, it’s obvious that the “predicate” parameter of this instruction represents that sgt and other predicates.

    But how do you know which class to look at. This is easily done with the LLVM C++ backend which dumps the equivalent C++ code needed to build some IR. For instance, given this piece of IR:

      %0 = load i32* %argc.addr, align 4
      %cmp = icmp sgt i32 %0, 0
    

    It will dump:

      LoadInst* int32_19 = new LoadInst(ptr_argc_addr, "", false, label_entry_15);
      int32_19->setAlignment(4);
      ICmpInst* int1_cmp = new ICmpInst(*label_entry_15, ICmpInst::ICMP_SGT, int32_19, const_int32_8, "cmp");
      BranchInst::Create(label_if_then, label_if_else, int1_cmp, label_entry_15);
    

    So you know just from looking at it that you need ICmpInst, and also that the predicate is ICMP_SGT.

    To run the C++ backend on some textual IR in a .ll file you just do:

    llc -march=cpp -cppgen=program irfile.ll
    

    Hope this helps!

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

Sidebar

Related Questions

Can someone tell me how exactly works test ICMP? (One of methods to detect
Hi Can someone tell me why when I send broadcast ICMP Request, only router
Can someone please explain why maximum legal size of ICMP echo packet is calculated
I'm currently experimenting with the Icmp protocol and I would like to implement a
Is it possible to implement an ICMP ping in Go? The alternative is to
I have been trying to set the TTL on ICMP packets using the boost::asio::ip::unicast::hops
I'm sending a ICMP packet through a socket in iOS: struct sockaddr hostAddress; self->hostAddress.sa_family
While trying to figure out the best method to ping (ICMP) something from python,
Earlier, I asked this question: How can I perform a ping or traceroute using
I'm trying to create an ICMP ping test program in C but am having

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.