Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
OverflowInstAnalysis.cpp
Go to the documentation of this file.
1//==-- OverflowInstAnalysis.cpp - Utils to fold overflow insts ----*- C++ -*-=//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file holds routines to help analyse overflow instructions
10// and fold them into constants or other overflow instructions
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Analysis/OverflowInstAnalysis.h"
15#include "llvm/IR/Instructions.h"
16#include "llvm/IR/PatternMatch.h"
17
18using namespacellvm;
19using namespacellvm::PatternMatch;
20
21boolllvm::isCheckForZeroAndMulWithOverflow(Value *Op0,Value *Op1,bool IsAnd,
22Use *&Y) {
23CmpPredicate Pred;
24Value *X, *NotOp1;
25int XIdx;
26IntrinsicInst *II;
27
28if (!match(Op0,m_ICmp(Pred,m_Value(X),m_Zero())))
29returnfalse;
30
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))
37returnfalse;
38
39II = dyn_cast<IntrinsicInst>(Extract->getAggregateOperand());
40if (!II ||
41 !match(II,m_CombineOr(m_Intrinsic<Intrinsic::umul_with_overflow>(),
42 m_Intrinsic<Intrinsic::smul_with_overflow>())))
43returnfalse;
44
45if (II->getArgOperand(0) ==X)
46 XIdx = 0;
47elseif (II->getArgOperand(1) ==X)
48 XIdx = 1;
49else
50returnfalse;
51returntrue;
52 };
53
54bool Matched =
55 (IsAnd && Pred == ICmpInst::Predicate::ICMP_NE &&
56 matchMulOverflowCheck(Op1)) ||
57 (!IsAnd && Pred == ICmpInst::Predicate::ICMP_EQ &&
58match(Op1,m_Not(m_Value(NotOp1))) && matchMulOverflowCheck(NotOp1));
59
60if (!Matched)
61returnfalse;
62
63Y = &II->getArgOperandUse(!XIdx);
64returntrue;
65}
66
67boolllvm::isCheckForZeroAndMulWithOverflow(Value *Op0,Value *Op1,
68bool IsAnd) {
69Use *Y;
70returnisCheckForZeroAndMulWithOverflow(Op0, Op1, IsAnd,Y);
71}
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Instructions.h
II
uint64_t IntrinsicInst * II
Definition:NVVMIntrRange.cpp:51
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
OverflowInstAnalysis.h
PatternMatch.h
llvm::CmpPredicate
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition:CmpPredicate.h:22
llvm::IntrinsicInst
A wrapper class for inspecting calls to intrinsic functions.
Definition:IntrinsicInst.h:48
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition:Use.h:43
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::PatternMatch
Definition:PatternMatch.h:47
llvm::PatternMatch::match
bool match(Val *V, const Pattern &P)
Definition:PatternMatch.h:49
llvm::PatternMatch::m_Value
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition:PatternMatch.h:92
llvm::PatternMatch::m_ICmp
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Definition:PatternMatch.h:1627
llvm::PatternMatch::m_Not
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'.
Definition:PatternMatch.h:2467
llvm::PatternMatch::m_Zero
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
Definition:PatternMatch.h:612
llvm::PatternMatch::m_CombineOr
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
Definition:PatternMatch.h:239
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::isCheckForZeroAndMulWithOverflow
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,...
Definition:OverflowInstAnalysis.cpp:21

Generated on Thu Jul 17 2025 11:00:59 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp