mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
fe8f0ed2ee
This patch teaches decomposeBitTestICmp to look through truncate instructions on the input to the compare. If a truncate is found it will now return the pre-truncated Value and appropriately extend the APInt mask. This allows some code to be removed from InstSimplify that was doing this functionality. This allows InstCombine's bit test combining code to match a pre-truncate Value with the same Value appear with an 'and' on another icmp. Or it allows us to combine a truncate to i16 and a truncate to i8. This also required removing the type check from the beginning of getMaskedTypeForICmpPair, but I believe that's ok because we still have to find two values from the input to each icmp that are equal before we'll do any transformation. So the type check was really just serving as an early out. There was one user of decomposeBitTestICmp that didn't want to look through truncates, so I've added a flag to prevent that behavior when necessary. Differential Revision: https://reviews.llvm.org/D37158 llvm-svn: 312382
73 lines
2.6 KiB
C++
73 lines
2.6 KiB
C++
//===-- CmpInstAnalysis.h - Utils to help fold compare insts ----*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file holds routines to help analyse compare instructions
|
|
// and fold them into constants or other compare instructions
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_ANALYSIS_CMPINSTANALYSIS_H
|
|
#define LLVM_ANALYSIS_CMPINSTANALYSIS_H
|
|
|
|
#include "llvm/IR/InstrTypes.h"
|
|
|
|
namespace llvm {
|
|
class ICmpInst;
|
|
class Value;
|
|
|
|
/// Encode a icmp predicate into a three bit mask. These bits are carefully
|
|
/// arranged to allow folding of expressions such as:
|
|
///
|
|
/// (A < B) | (A > B) --> (A != B)
|
|
///
|
|
/// Note that this is only valid if the first and second predicates have the
|
|
/// same sign. It is illegal to do: (A u< B) | (A s> B)
|
|
///
|
|
/// Three bits are used to represent the condition, as follows:
|
|
/// 0 A > B
|
|
/// 1 A == B
|
|
/// 2 A < B
|
|
///
|
|
/// <=> Value Definition
|
|
/// 000 0 Always false
|
|
/// 001 1 A > B
|
|
/// 010 2 A == B
|
|
/// 011 3 A >= B
|
|
/// 100 4 A < B
|
|
/// 101 5 A != B
|
|
/// 110 6 A <= B
|
|
/// 111 7 Always true
|
|
///
|
|
unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred = false);
|
|
|
|
/// This is the complement of getICmpCode, which turns an opcode and two
|
|
/// operands into either a constant true or false, or the predicate for a new
|
|
/// ICmp instruction. The sign is passed in to determine which kind of
|
|
/// predicate to use in the new icmp instruction.
|
|
/// Non-NULL return value will be a true or false constant.
|
|
/// NULL return means a new ICmp is needed. The predicate for which is output
|
|
/// in NewICmpPred.
|
|
Value *getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS,
|
|
CmpInst::Predicate &NewICmpPred);
|
|
|
|
/// Return true if both predicates match sign or if at least one of them is an
|
|
/// equality comparison (which is signless).
|
|
bool PredicatesFoldable(CmpInst::Predicate p1, CmpInst::Predicate p2);
|
|
|
|
/// Decompose an icmp into the form ((X & Mask) pred 0) if possible. The
|
|
/// returned predicate is either == or !=. Returns false if decomposition
|
|
/// fails.
|
|
bool decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate &Pred,
|
|
Value *&X, APInt &Mask,
|
|
bool LookThroughTrunc = true);
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|