[InstCombine] Signed saturation patterns
[llvm-complete.git] / lib / Analysis / PtrUseVisitor.cpp
blob9a834ba4866a278419a7f0ce51392c43d5cddbf7
1 //===- PtrUseVisitor.cpp - InstVisitors over a pointers uses --------------===//
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 /// \file
10 /// Implementation of the pointer use visitors.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Analysis/PtrUseVisitor.h"
15 #include "llvm/IR/Instruction.h"
16 #include "llvm/IR/Instructions.h"
17 #include <algorithm>
19 using namespace llvm;
21 void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) {
22 for (Use &U : I.uses()) {
23 if (VisitedUses.insert(&U).second) {
24 UseToVisit NewU = {
25 UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
26 Offset
28 Worklist.push_back(std::move(NewU));
33 bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) {
34 if (!IsOffsetKnown)
35 return false;
37 APInt TmpOffset(DL.getIndexTypeSizeInBits(GEPI.getType()), 0);
38 if (GEPI.accumulateConstantOffset(DL, TmpOffset)) {
39 Offset += TmpOffset.sextOrTrunc(Offset.getBitWidth());
40 return true;
43 return false;