1 //===-- CmpInstAnalysis.h - Utils to help fold compare insts ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file holds routines to help analyse compare instructions
11 // and fold them into constants or other compare instructions
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_UTILS_CMPINSTANALYSIS_H
16 #define LLVM_TRANSFORMS_UTILS_CMPINSTANALYSIS_H
18 #include "llvm/IR/InstrTypes.h"
24 /// getICmpCode - Encode a icmp predicate into a three bit mask. These bits
25 /// are carefully arranged to allow folding of expressions such as:
27 /// (A < B) | (A > B) --> (A != B)
29 /// Note that this is only valid if the first and second predicates have the
30 /// same sign. Is illegal to do: (A u< B) | (A s> B)
32 /// Three bits are used to represent the condition, as follows:
37 /// <=> Value Definition
38 /// 000 0 Always false
47 unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred = false);
49 /// getICmpValue - This is the complement of getICmpCode, which turns an
50 /// opcode and two operands into either a constant true or false, or the
51 /// predicate for a new ICmp instruction. The sign is passed in to determine
52 /// which kind of predicate to use in the 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 for which is
55 /// output in NewICmpPred.
56 Value *getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS,
57 CmpInst::Predicate &NewICmpPred);
59 /// PredicatesFoldable - Return true if both predicates match sign or if at
60 /// least one of them is an equality comparison (which is signless).
61 bool PredicatesFoldable(CmpInst::Predicate p1, CmpInst::Predicate p2);
63 } // end namespace llvm