1//==-- OverflowInstAnalysis.cpp - Utils to fold overflow insts ----*- C++ -*-=// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file holds routines to help analyse overflow instructions 10// and fold them into constants or other overflow instructions 12//===----------------------------------------------------------------------===// 31 /// %Agg = call { i4, i1 } @llvm.[us]mul.with.overflow.i4(i4 %X, i4 %???) 32 /// %V = extractvalue { i4, i1 } %Agg, 1 33auto matchMulOverflowCheck = [
X, &
II, &XIdx](
Value *V) {
34auto *Extract = dyn_cast<ExtractValueInst>(V);
35// We should only be extracting the overflow bit. 36if (!Extract || !Extract->getIndices().equals(1))
39II = dyn_cast<IntrinsicInst>(Extract->getAggregateOperand());
42 m_Intrinsic<Intrinsic::smul_with_overflow>())))
45if (
II->getArgOperand(0) ==
X)
47elseif (
II->getArgOperand(1) ==
X)
55 (IsAnd && Pred == ICmpInst::Predicate::ICMP_NE &&
56 matchMulOverflowCheck(Op1)) ||
57 (!IsAnd && Pred == ICmpInst::Predicate::ICMP_EQ &&
63Y = &
II->getArgOperandUse(!XIdx);
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
A wrapper class for inspecting calls to intrinsic functions.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
bool match(Val *V, const Pattern &P)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
This is an optimization pass for GlobalISel generic memory operations.
bool isCheckForZeroAndMulWithOverflow(Value *Op0, Value *Op1, bool IsAnd, Use *&Y)
Match one of the patterns up to the select/logic op: Op0 = icmp ne i4 X, 0 Agg = call { i4,...