LLVM  8.0.1
CmpInstAnalysis.h
Go to the documentation of this file.
1 //===-- CmpInstAnalysis.h - Utils to help fold compare insts ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file holds routines to help analyse compare instructions
11 // and fold them into constants or other compare instructions
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ANALYSIS_CMPINSTANALYSIS_H
16 #define LLVM_ANALYSIS_CMPINSTANALYSIS_H
17 
18 #include "llvm/IR/InstrTypes.h"
19 
20 namespace llvm {
21  class ICmpInst;
22  class Value;
23 
24  /// Encode a icmp predicate into a three bit mask. These bits are carefully
25  /// arranged to allow folding of expressions such as:
26  ///
27  /// (A < B) | (A > B) --> (A != B)
28  ///
29  /// Note that this is only valid if the first and second predicates have the
30  /// same sign. It is illegal to do: (A u< B) | (A s> B)
31  ///
32  /// Three bits are used to represent the condition, as follows:
33  /// 0 A > B
34  /// 1 A == B
35  /// 2 A < B
36  ///
37  /// <=> Value Definition
38  /// 000 0 Always false
39  /// 001 1 A > B
40  /// 010 2 A == B
41  /// 011 3 A >= B
42  /// 100 4 A < B
43  /// 101 5 A != B
44  /// 110 6 A <= B
45  /// 111 7 Always true
46  ///
47  unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred = false);
48 
49  /// This is the complement of getICmpCode. It turns a predicate code into
50  /// either a constant true or false or the predicate for a new ICmp.
51  /// The sign is passed in to determine which kind of predicate to use in the
52  /// new ICmp instruction.
53  /// Non-NULL return value will be a true or false constant.
54  /// NULL return means a new ICmp is needed. The predicate is output in Pred.
55  Constant *getPredForICmpCode(unsigned Code, bool Sign, Type *OpTy,
56  CmpInst::Predicate &Pred);
57 
58  /// Return true if both predicates match sign or if at least one of them is an
59  /// equality comparison (which is signless).
61 
62  /// Decompose an icmp into the form ((X & Mask) pred 0) if possible. The
63  /// returned predicate is either == or !=. Returns false if decomposition
64  /// fails.
65  bool decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate &Pred,
66  Value *&X, APInt &Mask,
67  bool LookThroughTrunc = true);
68 
69 } // end namespace llvm
70 
71 #endif
Constant * getPredForICmpCode(unsigned Code, bool Sign, Type *OpTy, CmpInst::Predicate &Pred)
This is the complement of getICmpCode.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate &Pred, Value *&X, APInt &Mask, bool LookThroughTrunc=true)
Decompose an icmp into the form ((X & Mask) pred 0) if possible.
unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred=false)
Encode a icmp predicate into a three bit mask.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:646
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
bool predicatesFoldable(CmpInst::Predicate P1, CmpInst::Predicate P2)
Return true if both predicates match sign or if at least one of them is an equality comparison (which...