LLVM  14.0.0git
InstCombineCalls.cpp
Go to the documentation of this file.
1 //===- InstCombineCalls.cpp -----------------------------------------------===//
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 implements the visitCall, visitInvoke, and visitCallBr functions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "InstCombineInternal.h"
14 #include "llvm/ADT/APFloat.h"
15 #include "llvm/ADT/APInt.h"
16 #include "llvm/ADT/APSInt.h"
17 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/STLExtras.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/Statistic.h"
25 #include "llvm/ADT/Twine.h"
30 #include "llvm/Analysis/Loads.h"
35 #include "llvm/IR/Attributes.h"
36 #include "llvm/IR/BasicBlock.h"
37 #include "llvm/IR/Constant.h"
38 #include "llvm/IR/Constants.h"
39 #include "llvm/IR/DataLayout.h"
40 #include "llvm/IR/DerivedTypes.h"
41 #include "llvm/IR/Function.h"
42 #include "llvm/IR/GlobalVariable.h"
43 #include "llvm/IR/InlineAsm.h"
44 #include "llvm/IR/InstrTypes.h"
45 #include "llvm/IR/Instruction.h"
46 #include "llvm/IR/Instructions.h"
47 #include "llvm/IR/IntrinsicInst.h"
48 #include "llvm/IR/Intrinsics.h"
49 #include "llvm/IR/IntrinsicsAArch64.h"
50 #include "llvm/IR/IntrinsicsAMDGPU.h"
51 #include "llvm/IR/IntrinsicsARM.h"
52 #include "llvm/IR/IntrinsicsHexagon.h"
53 #include "llvm/IR/LLVMContext.h"
54 #include "llvm/IR/Metadata.h"
55 #include "llvm/IR/PatternMatch.h"
56 #include "llvm/IR/Statepoint.h"
57 #include "llvm/IR/Type.h"
58 #include "llvm/IR/User.h"
59 #include "llvm/IR/Value.h"
60 #include "llvm/IR/ValueHandle.h"
62 #include "llvm/Support/Casting.h"
64 #include "llvm/Support/Compiler.h"
65 #include "llvm/Support/Debug.h"
67 #include "llvm/Support/KnownBits.h"
75 #include <algorithm>
76 #include <cassert>
77 #include <cstdint>
78 #include <cstring>
79 #include <utility>
80 #include <vector>
81 
82 using namespace llvm;
83 using namespace PatternMatch;
84 
85 #define DEBUG_TYPE "instcombine"
86 
87 STATISTIC(NumSimplified, "Number of library calls simplified");
88 
90  "instcombine-guard-widening-window",
91  cl::init(3),
92  cl::desc("How wide an instruction window to bypass looking for "
93  "another guard"));
94 
95 namespace llvm {
96 /// enable preservation of attributes in assume like:
97 /// call void @llvm.assume(i1 true) [ "nonnull"(i32* %PTR) ]
99 } // namespace llvm
100 
101 /// Return the specified type promoted as it would be to pass though a va_arg
102 /// area.
103 static Type *getPromotedType(Type *Ty) {
104  if (IntegerType* ITy = dyn_cast<IntegerType>(Ty)) {
105  if (ITy->getBitWidth() < 32)
106  return Type::getInt32Ty(Ty->getContext());
107  }
108  return Ty;
109 }
110 
112  Align DstAlign = getKnownAlignment(MI->getRawDest(), DL, MI, &AC, &DT);
113  MaybeAlign CopyDstAlign = MI->getDestAlign();
114  if (!CopyDstAlign || *CopyDstAlign < DstAlign) {
115  MI->setDestAlignment(DstAlign);
116  return MI;
117  }
118 
119  Align SrcAlign = getKnownAlignment(MI->getRawSource(), DL, MI, &AC, &DT);
120  MaybeAlign CopySrcAlign = MI->getSourceAlign();
121  if (!CopySrcAlign || *CopySrcAlign < SrcAlign) {
122  MI->setSourceAlignment(SrcAlign);
123  return MI;
124  }
125 
126  // If we have a store to a location which is known constant, we can conclude
127  // that the store must be storing the constant value (else the memory
128  // wouldn't be constant), and this must be a noop.
129  if (AA->pointsToConstantMemory(MI->getDest())) {
130  // Set the size of the copy to 0, it will be deleted on the next iteration.
131  MI->setLength(Constant::getNullValue(MI->getLength()->getType()));
132  return MI;
133  }
134 
135  // If MemCpyInst length is 1/2/4/8 bytes then replace memcpy with
136  // load/store.
137  ConstantInt *MemOpLength = dyn_cast<ConstantInt>(MI->getLength());
138  if (!MemOpLength) return nullptr;
139 
140  // Source and destination pointer types are always "i8*" for intrinsic. See
141  // if the size is something we can handle with a single primitive load/store.
142  // A single load+store correctly handles overlapping memory in the memmove
143  // case.
144  uint64_t Size = MemOpLength->getLimitedValue();
145  assert(Size && "0-sized memory transferring should be removed already.");
146 
147  if (Size > 8 || (Size&(Size-1)))
148  return nullptr; // If not 1/2/4/8 bytes, exit.
149 
150  // If it is an atomic and alignment is less than the size then we will
151  // introduce the unaligned memory access which will be later transformed
152  // into libcall in CodeGen. This is not evident performance gain so disable
153  // it now.
154  if (isa<AtomicMemTransferInst>(MI))
155  if (*CopyDstAlign < Size || *CopySrcAlign < Size)
156  return nullptr;
157 
158  // Use an integer load+store unless we can find something better.
159  unsigned SrcAddrSp =
160  cast<PointerType>(MI->getArgOperand(1)->getType())->getAddressSpace();
161  unsigned DstAddrSp =
162  cast<PointerType>(MI->getArgOperand(0)->getType())->getAddressSpace();
163 
164  IntegerType* IntType = IntegerType::get(MI->getContext(), Size<<3);
165  Type *NewSrcPtrTy = PointerType::get(IntType, SrcAddrSp);
166  Type *NewDstPtrTy = PointerType::get(IntType, DstAddrSp);
167 
168  // If the memcpy has metadata describing the members, see if we can get the
169  // TBAA tag describing our copy.
170  MDNode *CopyMD = nullptr;
171  if (MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa)) {
172  CopyMD = M;
173  } else if (MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa_struct)) {
174  if (M->getNumOperands() == 3 && M->getOperand(0) &&
175  mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
176  mdconst::extract<ConstantInt>(M->getOperand(0))->isZero() &&
177  M->getOperand(1) &&
178  mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
179  mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
180  Size &&
181  M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
182  CopyMD = cast<MDNode>(M->getOperand(2));
183  }
184 
185  Value *Src = Builder.CreateBitCast(MI->getArgOperand(1), NewSrcPtrTy);
186  Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
187  LoadInst *L = Builder.CreateLoad(IntType, Src);
188  // Alignment from the mem intrinsic will be better, so use it.
189  L->setAlignment(*CopySrcAlign);
190  if (CopyMD)
191  L->setMetadata(LLVMContext::MD_tbaa, CopyMD);
192  MDNode *LoopMemParallelMD =
193  MI->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
194  if (LoopMemParallelMD)
195  L->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
196  MDNode *AccessGroupMD = MI->getMetadata(LLVMContext::MD_access_group);
197  if (AccessGroupMD)
198  L->setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
199 
200  StoreInst *S = Builder.CreateStore(L, Dest);
201  // Alignment from the mem intrinsic will be better, so use it.
202  S->setAlignment(*CopyDstAlign);
203  if (CopyMD)
204  S->setMetadata(LLVMContext::MD_tbaa, CopyMD);
205  if (LoopMemParallelMD)
206  S->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
207  if (AccessGroupMD)
208  S->setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
209 
210  if (auto *MT = dyn_cast<MemTransferInst>(MI)) {
211  // non-atomics can be volatile
212  L->setVolatile(MT->isVolatile());
213  S->setVolatile(MT->isVolatile());
214  }
215  if (isa<AtomicMemTransferInst>(MI)) {
216  // atomics have to be unordered
218  S->setOrdering(AtomicOrdering::Unordered);
219  }
220 
221  // Set the size of the copy to 0, it will be deleted on the next iteration.
222  MI->setLength(Constant::getNullValue(MemOpLength->getType()));
223  return MI;
224 }
225 
227  const Align KnownAlignment =
228  getKnownAlignment(MI->getDest(), DL, MI, &AC, &DT);
229  MaybeAlign MemSetAlign = MI->getDestAlign();
230  if (!MemSetAlign || *MemSetAlign < KnownAlignment) {
231  MI->setDestAlignment(KnownAlignment);
232  return MI;
233  }
234 
235  // If we have a store to a location which is known constant, we can conclude
236  // that the store must be storing the constant value (else the memory
237  // wouldn't be constant), and this must be a noop.
238  if (AA->pointsToConstantMemory(MI->getDest())) {
239  // Set the size of the copy to 0, it will be deleted on the next iteration.
240  MI->setLength(Constant::getNullValue(MI->getLength()->getType()));
241  return MI;
242  }
243 
244  // Extract the length and alignment and fill if they are constant.
245  ConstantInt *LenC = dyn_cast<ConstantInt>(MI->getLength());
246  ConstantInt *FillC = dyn_cast<ConstantInt>(MI->getValue());
247  if (!LenC || !FillC || !FillC->getType()->isIntegerTy(8))
248  return nullptr;
249  const uint64_t Len = LenC->getLimitedValue();
250  assert(Len && "0-sized memory setting should be removed already.");
251  const Align Alignment = assumeAligned(MI->getDestAlignment());
252 
253  // If it is an atomic and alignment is less than the size then we will
254  // introduce the unaligned memory access which will be later transformed
255  // into libcall in CodeGen. This is not evident performance gain so disable
256  // it now.
257  if (isa<AtomicMemSetInst>(MI))
258  if (Alignment < Len)
259  return nullptr;
260 
261  // memset(s,c,n) -> store s, c (for n=1,2,4,8)
262  if (Len <= 8 && isPowerOf2_32((uint32_t)Len)) {
263  Type *ITy = IntegerType::get(MI->getContext(), Len*8); // n=1 -> i8.
264 
265  Value *Dest = MI->getDest();
266  unsigned DstAddrSp = cast<PointerType>(Dest->getType())->getAddressSpace();
267  Type *NewDstPtrTy = PointerType::get(ITy, DstAddrSp);
268  Dest = Builder.CreateBitCast(Dest, NewDstPtrTy);
269 
270  // Extract the fill value and store.
271  uint64_t Fill = FillC->getZExtValue()*0x0101010101010101ULL;
272  StoreInst *S = Builder.CreateStore(ConstantInt::get(ITy, Fill), Dest,
273  MI->isVolatile());
274  S->setAlignment(Alignment);
275  if (isa<AtomicMemSetInst>(MI))
276  S->setOrdering(AtomicOrdering::Unordered);
277 
278  // Set the size of the copy to 0, it will be deleted on the next iteration.
279  MI->setLength(Constant::getNullValue(LenC->getType()));
280  return MI;
281  }
282 
283  return nullptr;
284 }
285 
286 // TODO, Obvious Missing Transforms:
287 // * Narrow width by halfs excluding zero/undef lanes
288 Value *InstCombinerImpl::simplifyMaskedLoad(IntrinsicInst &II) {
289  Value *LoadPtr = II.getArgOperand(0);
290  const Align Alignment =
291  cast<ConstantInt>(II.getArgOperand(1))->getAlignValue();
292 
293  // If the mask is all ones or undefs, this is a plain vector load of the 1st
294  // argument.
295  if (maskIsAllOneOrUndef(II.getArgOperand(2))) {
296  LoadInst *L = Builder.CreateAlignedLoad(II.getType(), LoadPtr, Alignment,
297  "unmaskedload");
298  L->copyMetadata(II);
299  return L;
300  }
301 
302  // If we can unconditionally load from this address, replace with a
303  // load/select idiom. TODO: use DT for context sensitive query
304  if (isDereferenceablePointer(LoadPtr, II.getType(),
305  II.getModule()->getDataLayout(), &II, nullptr)) {
306  LoadInst *LI = Builder.CreateAlignedLoad(II.getType(), LoadPtr, Alignment,
307  "unmaskedload");
308  LI->copyMetadata(II);
309  return Builder.CreateSelect(II.getArgOperand(2), LI, II.getArgOperand(3));
310  }
311 
312  return nullptr;
313 }
314 
315 // TODO, Obvious Missing Transforms:
316 // * Single constant active lane -> store
317 // * Narrow width by halfs excluding zero/undef lanes
318 Instruction *InstCombinerImpl::simplifyMaskedStore(IntrinsicInst &II) {
319  auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(3));
320  if (!ConstMask)
321  return nullptr;
322 
323  // If the mask is all zeros, this instruction does nothing.
324  if (ConstMask->isNullValue())
325  return eraseInstFromFunction(II);
326 
327  // If the mask is all ones, this is a plain vector store of the 1st argument.
328  if (ConstMask->isAllOnesValue()) {
329  Value *StorePtr = II.getArgOperand(1);
330  Align Alignment = cast<ConstantInt>(II.getArgOperand(2))->getAlignValue();
331  StoreInst *S =
332  new StoreInst(II.getArgOperand(0), StorePtr, false, Alignment);
333  S->copyMetadata(II);
334  return S;
335  }
336 
337  if (isa<ScalableVectorType>(ConstMask->getType()))
338  return nullptr;
339 
340  // Use masked off lanes to simplify operands via SimplifyDemandedVectorElts
341  APInt DemandedElts = possiblyDemandedEltsInMask(ConstMask);
342  APInt UndefElts(DemandedElts.getBitWidth(), 0);
343  if (Value *V =
344  SimplifyDemandedVectorElts(II.getOperand(0), DemandedElts, UndefElts))
345  return replaceOperand(II, 0, V);
346 
347  return nullptr;
348 }
349 
350 // TODO, Obvious Missing Transforms:
351 // * Single constant active lane load -> load
352 // * Dereferenceable address & few lanes -> scalarize speculative load/selects
353 // * Adjacent vector addresses -> masked.load
354 // * Narrow width by halfs excluding zero/undef lanes
355 // * Vector splat address w/known mask -> scalar load
356 // * Vector incrementing address -> vector masked load
357 Instruction *InstCombinerImpl::simplifyMaskedGather(IntrinsicInst &II) {
358  return nullptr;
359 }
360 
361 // TODO, Obvious Missing Transforms:
362 // * Single constant active lane -> store
363 // * Adjacent vector addresses -> masked.store
364 // * Narrow store width by halfs excluding zero/undef lanes
365 // * Vector splat address w/known mask -> scalar store
366 // * Vector incrementing address -> vector masked store
367 Instruction *InstCombinerImpl::simplifyMaskedScatter(IntrinsicInst &II) {
368  auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(3));
369  if (!ConstMask)
370  return nullptr;
371 
372  // If the mask is all zeros, a scatter does nothing.
373  if (ConstMask->isNullValue())
374  return eraseInstFromFunction(II);
375 
376  if (isa<ScalableVectorType>(ConstMask->getType()))
377  return nullptr;
378 
379  // Use masked off lanes to simplify operands via SimplifyDemandedVectorElts
380  APInt DemandedElts = possiblyDemandedEltsInMask(ConstMask);
381  APInt UndefElts(DemandedElts.getBitWidth(), 0);
382  if (Value *V =
383  SimplifyDemandedVectorElts(II.getOperand(0), DemandedElts, UndefElts))
384  return replaceOperand(II, 0, V);
385  if (Value *V =
386  SimplifyDemandedVectorElts(II.getOperand(1), DemandedElts, UndefElts))
387  return replaceOperand(II, 1, V);
388 
389  return nullptr;
390 }
391 
392 /// This function transforms launder.invariant.group and strip.invariant.group
393 /// like:
394 /// launder(launder(%x)) -> launder(%x) (the result is not the argument)
395 /// launder(strip(%x)) -> launder(%x)
396 /// strip(strip(%x)) -> strip(%x) (the result is not the argument)
397 /// strip(launder(%x)) -> strip(%x)
398 /// This is legal because it preserves the most recent information about
399 /// the presence or absence of invariant.group.
401  InstCombinerImpl &IC) {
402  auto *Arg = II.getArgOperand(0);
403  auto *StrippedArg = Arg->stripPointerCasts();
404  auto *StrippedInvariantGroupsArg = StrippedArg;
405  while (auto *Intr = dyn_cast<IntrinsicInst>(StrippedInvariantGroupsArg)) {
406  if (Intr->getIntrinsicID() != Intrinsic::launder_invariant_group &&
407  Intr->getIntrinsicID() != Intrinsic::strip_invariant_group)
408  break;
409  StrippedInvariantGroupsArg = Intr->getArgOperand(0)->stripPointerCasts();
410  }
411  if (StrippedArg == StrippedInvariantGroupsArg)
412  return nullptr; // No launders/strips to remove.
413 
414  Value *Result = nullptr;
415 
416  if (II.getIntrinsicID() == Intrinsic::launder_invariant_group)
417  Result = IC.Builder.CreateLaunderInvariantGroup(StrippedInvariantGroupsArg);
418  else if (II.getIntrinsicID() == Intrinsic::strip_invariant_group)
419  Result = IC.Builder.CreateStripInvariantGroup(StrippedInvariantGroupsArg);
420  else
422  "simplifyInvariantGroupIntrinsic only handles launder and strip");
423  if (Result->getType()->getPointerAddressSpace() !=
425  Result = IC.Builder.CreateAddrSpaceCast(Result, II.getType());
426  if (Result->getType() != II.getType())
427  Result = IC.Builder.CreateBitCast(Result, II.getType());
428 
429  return cast<Instruction>(Result);
430 }
431 
433  assert((II.getIntrinsicID() == Intrinsic::cttz ||
434  II.getIntrinsicID() == Intrinsic::ctlz) &&
435  "Expected cttz or ctlz intrinsic");
436  bool IsTZ = II.getIntrinsicID() == Intrinsic::cttz;
437  Value *Op0 = II.getArgOperand(0);
438  Value *Op1 = II.getArgOperand(1);
439  Value *X;
440  // ctlz(bitreverse(x)) -> cttz(x)
441  // cttz(bitreverse(x)) -> ctlz(x)
442  if (match(Op0, m_BitReverse(m_Value(X)))) {
443  Intrinsic::ID ID = IsTZ ? Intrinsic::ctlz : Intrinsic::cttz;
445  return CallInst::Create(F, {X, II.getArgOperand(1)});
446  }
447 
448  if (II.getType()->isIntOrIntVectorTy(1)) {
449  // ctlz/cttz i1 Op0 --> not Op0
450  if (match(Op1, m_Zero()))
451  return BinaryOperator::CreateNot(Op0);
452  // If zero is undef, then the input can be assumed to be "true", so the
453  // instruction simplifies to "false".
454  assert(match(Op1, m_One()) && "Expected ctlz/cttz operand to be 0 or 1");
456  }
457 
458  // If the operand is a select with constant arm(s), try to hoist ctlz/cttz.
459  if (auto *Sel = dyn_cast<SelectInst>(Op0))
460  if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
461  return R;
462 
463  if (IsTZ) {
464  // cttz(-x) -> cttz(x)
465  if (match(Op0, m_Neg(m_Value(X))))
466  return IC.replaceOperand(II, 0, X);
467 
468  // cttz(sext(x)) -> cttz(zext(x))
469  if (match(Op0, m_OneUse(m_SExt(m_Value(X))))) {
470  auto *Zext = IC.Builder.CreateZExt(X, II.getType());
471  auto *CttzZext =
472  IC.Builder.CreateBinaryIntrinsic(Intrinsic::cttz, Zext, Op1);
473  return IC.replaceInstUsesWith(II, CttzZext);
474  }
475 
476  // Zext doesn't change the number of trailing zeros, so narrow:
477  // cttz(zext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true'.
478  if (match(Op0, m_OneUse(m_ZExt(m_Value(X)))) && match(Op1, m_One())) {
479  auto *Cttz = IC.Builder.CreateBinaryIntrinsic(Intrinsic::cttz, X,
480  IC.Builder.getTrue());
481  auto *ZextCttz = IC.Builder.CreateZExt(Cttz, II.getType());
482  return IC.replaceInstUsesWith(II, ZextCttz);
483  }
484 
485  // cttz(abs(x)) -> cttz(x)
486  // cttz(nabs(x)) -> cttz(x)
487  Value *Y;
489  if (SPF == SPF_ABS || SPF == SPF_NABS)
490  return IC.replaceOperand(II, 0, X);
491 
492  if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X))))
493  return IC.replaceOperand(II, 0, X);
494  }
495 
496  KnownBits Known = IC.computeKnownBits(Op0, 0, &II);
497 
498  // Create a mask for bits above (ctlz) or below (cttz) the first known one.
499  unsigned PossibleZeros = IsTZ ? Known.countMaxTrailingZeros()
500  : Known.countMaxLeadingZeros();
501  unsigned DefiniteZeros = IsTZ ? Known.countMinTrailingZeros()
502  : Known.countMinLeadingZeros();
503 
504  // If all bits above (ctlz) or below (cttz) the first known one are known
505  // zero, this value is constant.
506  // FIXME: This should be in InstSimplify because we're replacing an
507  // instruction with a constant.
508  if (PossibleZeros == DefiniteZeros) {
509  auto *C = ConstantInt::get(Op0->getType(), DefiniteZeros);
510  return IC.replaceInstUsesWith(II, C);
511  }
512 
513  // If the input to cttz/ctlz is known to be non-zero,
514  // then change the 'ZeroIsUndef' parameter to 'true'
515  // because we know the zero behavior can't affect the result.
516  if (!Known.One.isNullValue() ||
517  isKnownNonZero(Op0, IC.getDataLayout(), 0, &IC.getAssumptionCache(), &II,
518  &IC.getDominatorTree())) {
519  if (!match(II.getArgOperand(1), m_One()))
520  return IC.replaceOperand(II, 1, IC.Builder.getTrue());
521  }
522 
523  // Add range metadata since known bits can't completely reflect what we know.
524  // TODO: Handle splat vectors.
525  auto *IT = dyn_cast<IntegerType>(Op0->getType());
526  if (IT && IT->getBitWidth() != 1 && !II.getMetadata(LLVMContext::MD_range)) {
527  Metadata *LowAndHigh[] = {
529  ConstantAsMetadata::get(ConstantInt::get(IT, PossibleZeros + 1))};
530  II.setMetadata(LLVMContext::MD_range,
532  return &II;
533  }
534 
535  return nullptr;
536 }
537 
539  assert(II.getIntrinsicID() == Intrinsic::ctpop &&
540  "Expected ctpop intrinsic");
541  Type *Ty = II.getType();
542  unsigned BitWidth = Ty->getScalarSizeInBits();
543  Value *Op0 = II.getArgOperand(0);
544  Value *X, *Y;
545 
546  // ctpop(bitreverse(x)) -> ctpop(x)
547  // ctpop(bswap(x)) -> ctpop(x)
548  if (match(Op0, m_BitReverse(m_Value(X))) || match(Op0, m_BSwap(m_Value(X))))
549  return IC.replaceOperand(II, 0, X);
550 
551  // ctpop(rot(x)) -> ctpop(x)
552  if ((match(Op0, m_FShl(m_Value(X), m_Value(Y), m_Value())) ||
553  match(Op0, m_FShr(m_Value(X), m_Value(Y), m_Value()))) &&
554  X == Y)
555  return IC.replaceOperand(II, 0, X);
556 
557  // ctpop(x | -x) -> bitwidth - cttz(x, false)
558  if (Op0->hasOneUse() &&
559  match(Op0, m_c_Or(m_Value(X), m_Neg(m_Deferred(X))))) {
560  Function *F =
561  Intrinsic::getDeclaration(II.getModule(), Intrinsic::cttz, Ty);
562  auto *Cttz = IC.Builder.CreateCall(F, {X, IC.Builder.getFalse()});
563  auto *Bw = ConstantInt::get(Ty, APInt(BitWidth, BitWidth));
564  return IC.replaceInstUsesWith(II, IC.Builder.CreateSub(Bw, Cttz));
565  }
566 
567  // ctpop(~x & (x - 1)) -> cttz(x, false)
568  if (match(Op0,
570  Function *F =
571  Intrinsic::getDeclaration(II.getModule(), Intrinsic::cttz, Ty);
572  return CallInst::Create(F, {X, IC.Builder.getFalse()});
573  }
574 
575  // Zext doesn't change the number of set bits, so narrow:
576  // ctpop (zext X) --> zext (ctpop X)
577  if (match(Op0, m_OneUse(m_ZExt(m_Value(X))))) {
578  Value *NarrowPop = IC.Builder.CreateUnaryIntrinsic(Intrinsic::ctpop, X);
579  return CastInst::Create(Instruction::ZExt, NarrowPop, Ty);
580  }
581 
582  // If the operand is a select with constant arm(s), try to hoist ctpop.
583  if (auto *Sel = dyn_cast<SelectInst>(Op0))
584  if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
585  return R;
586 
587  KnownBits Known(BitWidth);
588  IC.computeKnownBits(Op0, Known, 0, &II);
589 
590  // If all bits are zero except for exactly one fixed bit, then the result
591  // must be 0 or 1, and we can get that answer by shifting to LSB:
592  // ctpop (X & 32) --> (X & 32) >> 5
593  if ((~Known.Zero).isPowerOf2())
594  return BinaryOperator::CreateLShr(
595  Op0, ConstantInt::get(Ty, (~Known.Zero).exactLogBase2()));
596 
597  // FIXME: Try to simplify vectors of integers.
598  auto *IT = dyn_cast<IntegerType>(Ty);
599  if (!IT)
600  return nullptr;
601 
602  // Add range metadata since known bits can't completely reflect what we know.
603  unsigned MinCount = Known.countMinPopulation();
604  unsigned MaxCount = Known.countMaxPopulation();
605  if (IT->getBitWidth() != 1 && !II.getMetadata(LLVMContext::MD_range)) {
606  Metadata *LowAndHigh[] = {
609  II.setMetadata(LLVMContext::MD_range,
611  return &II;
612  }
613 
614  return nullptr;
615 }
616 
617 /// Convert a table lookup to shufflevector if the mask is constant.
618 /// This could benefit tbl1 if the mask is { 7,6,5,4,3,2,1,0 }, in
619 /// which case we could lower the shufflevector with rev64 instructions
620 /// as it's actually a byte reverse.
623  // Bail out if the mask is not a constant.
624  auto *C = dyn_cast<Constant>(II.getArgOperand(1));
625  if (!C)
626  return nullptr;
627 
628  auto *VecTy = cast<FixedVectorType>(II.getType());
629  unsigned NumElts = VecTy->getNumElements();
630 
631  // Only perform this transformation for <8 x i8> vector types.
632  if (!VecTy->getElementType()->isIntegerTy(8) || NumElts != 8)
633  return nullptr;
634 
635  int Indexes[8];
636 
637  for (unsigned I = 0; I < NumElts; ++I) {
638  Constant *COp = C->getAggregateElement(I);
639 
640  if (!COp || !isa<ConstantInt>(COp))
641  return nullptr;
642 
643  Indexes[I] = cast<ConstantInt>(COp)->getLimitedValue();
644 
645  // Make sure the mask indices are in range.
646  if ((unsigned)Indexes[I] >= NumElts)
647  return nullptr;
648  }
649 
650  auto *V1 = II.getArgOperand(0);
651  auto *V2 = Constant::getNullValue(V1->getType());
652  return Builder.CreateShuffleVector(V1, V2, makeArrayRef(Indexes));
653 }
654 
655 // Returns true iff the 2 intrinsics have the same operands, limiting the
656 // comparison to the first NumOperands.
657 static bool haveSameOperands(const IntrinsicInst &I, const IntrinsicInst &E,
658  unsigned NumOperands) {
659  assert(I.getNumArgOperands() >= NumOperands && "Not enough operands");
660  assert(E.getNumArgOperands() >= NumOperands && "Not enough operands");
661  for (unsigned i = 0; i < NumOperands; i++)
662  if (I.getArgOperand(i) != E.getArgOperand(i))
663  return false;
664  return true;
665 }
666 
667 // Remove trivially empty start/end intrinsic ranges, i.e. a start
668 // immediately followed by an end (ignoring debuginfo or other
669 // start/end intrinsics in between). As this handles only the most trivial
670 // cases, tracking the nesting level is not needed:
671 //
672 // call @llvm.foo.start(i1 0)
673 // call @llvm.foo.start(i1 0) ; This one won't be skipped: it will be removed
674 // call @llvm.foo.end(i1 0)
675 // call @llvm.foo.end(i1 0) ; &I
676 static bool
678  std::function<bool(const IntrinsicInst &)> IsStart) {
679  // We start from the end intrinsic and scan backwards, so that InstCombine
680  // has already processed (and potentially removed) all the instructions
681  // before the end intrinsic.
682  BasicBlock::reverse_iterator BI(EndI), BE(EndI.getParent()->rend());
683  for (; BI != BE; ++BI) {
684  if (auto *I = dyn_cast<IntrinsicInst>(&*BI)) {
685  if (isa<DbgInfoIntrinsic>(I) ||
686  I->getIntrinsicID() == EndI.getIntrinsicID())
687  continue;
688  if (IsStart(*I)) {
689  if (haveSameOperands(EndI, *I, EndI.getNumArgOperands())) {
691  IC.eraseInstFromFunction(EndI);
692  return true;
693  }
694  // Skip start intrinsics that don't pair with this end intrinsic.
695  continue;
696  }
697  }
698  break;
699  }
700 
701  return false;
702 }
703 
705  removeTriviallyEmptyRange(I, *this, [](const IntrinsicInst &I) {
706  return I.getIntrinsicID() == Intrinsic::vastart ||
707  I.getIntrinsicID() == Intrinsic::vacopy;
708  });
709  return nullptr;
710 }
711 
713  assert(Call.getNumArgOperands() > 1 && "Need at least 2 args to swap");
714  Value *Arg0 = Call.getArgOperand(0), *Arg1 = Call.getArgOperand(1);
715  if (isa<Constant>(Arg0) && !isa<Constant>(Arg1)) {
716  Call.setArgOperand(0, Arg1);
717  Call.setArgOperand(1, Arg0);
718  return &Call;
719  }
720  return nullptr;
721 }
722 
723 /// Creates a result tuple for an overflow intrinsic \p II with a given
724 /// \p Result and a constant \p Overflow value.
726  Constant *Overflow) {
727  Constant *V[] = {UndefValue::get(Result->getType()), Overflow};
728  StructType *ST = cast<StructType>(II->getType());
729  Constant *Struct = ConstantStruct::get(ST, V);
730  return InsertValueInst::Create(Struct, Result, 0);
731 }
732 
733 Instruction *
734 InstCombinerImpl::foldIntrinsicWithOverflowCommon(IntrinsicInst *II) {
735  WithOverflowInst *WO = cast<WithOverflowInst>(II);
736  Value *OperationResult = nullptr;
737  Constant *OverflowResult = nullptr;
738  if (OptimizeOverflowCheck(WO->getBinaryOp(), WO->isSigned(), WO->getLHS(),
739  WO->getRHS(), *WO, OperationResult, OverflowResult))
740  return createOverflowTuple(WO, OperationResult, OverflowResult);
741  return nullptr;
742 }
743 
745  const DataLayout &DL, AssumptionCache *AC,
746  DominatorTree *DT) {
747  KnownBits Known = computeKnownBits(Op, DL, 0, AC, CxtI, DT);
748  if (Known.isNonNegative())
749  return false;
750  if (Known.isNegative())
751  return true;
752 
754  ICmpInst::ICMP_SLT, Op, Constant::getNullValue(Op->getType()), CxtI, DL);
755 }
756 
757 /// If we have a clamp pattern like max (min X, 42), 41 -- where the output
758 /// can only be one of two possible constant values -- turn that into a select
759 /// of constants.
762  Value *I0 = II->getArgOperand(0), *I1 = II->getArgOperand(1);
763  Value *X;
764  const APInt *C0, *C1;
765  if (!match(I1, m_APInt(C1)) || !I0->hasOneUse())
766  return nullptr;
767 
769  switch (II->getIntrinsicID()) {
770  case Intrinsic::smax:
771  if (match(I0, m_SMin(m_Value(X), m_APInt(C0))) && *C0 == *C1 + 1)
772  Pred = ICmpInst::ICMP_SGT;
773  break;
774  case Intrinsic::smin:
775  if (match(I0, m_SMax(m_Value(X), m_APInt(C0))) && *C1 == *C0 + 1)
776  Pred = ICmpInst::ICMP_SLT;
777  break;
778  case Intrinsic::umax:
779  if (match(I0, m_UMin(m_Value(X), m_APInt(C0))) && *C0 == *C1 + 1)
780  Pred = ICmpInst::ICMP_UGT;
781  break;
782  case Intrinsic::umin:
783  if (match(I0, m_UMax(m_Value(X), m_APInt(C0))) && *C1 == *C0 + 1)
784  Pred = ICmpInst::ICMP_ULT;
785  break;
786  default:
787  llvm_unreachable("Expected min/max intrinsic");
788  }
789  if (Pred == CmpInst::BAD_ICMP_PREDICATE)
790  return nullptr;
791 
792  // max (min X, 42), 41 --> X > 41 ? 42 : 41
793  // min (max X, 42), 43 --> X < 43 ? 42 : 43
794  Value *Cmp = Builder.CreateICmp(Pred, X, I1);
795  return SelectInst::Create(Cmp, ConstantInt::get(II->getType(), *C0), I1);
796 }
797 
798 /// CallInst simplification. This mostly only handles folding of intrinsic
799 /// instructions. For normal calls, it allows visitCallBase to do the heavy
800 /// lifting.
802  // Don't try to simplify calls without uses. It will not do anything useful,
803  // but will result in the following folds being skipped.
804  if (!CI.use_empty())
805  if (Value *V = SimplifyCall(&CI, SQ.getWithInstruction(&CI)))
806  return replaceInstUsesWith(CI, V);
807 
808  if (isFreeCall(&CI, &TLI))
809  return visitFree(CI);
810 
811  // If the caller function is nounwind, mark the call as nounwind, even if the
812  // callee isn't.
813  if (CI.getFunction()->doesNotThrow() && !CI.doesNotThrow()) {
814  CI.setDoesNotThrow();
815  return &CI;
816  }
817 
818  IntrinsicInst *II = dyn_cast<IntrinsicInst>(&CI);
819  if (!II) return visitCallBase(CI);
820 
821  // For atomic unordered mem intrinsics if len is not a positive or
822  // not a multiple of element size then behavior is undefined.
823  if (auto *AMI = dyn_cast<AtomicMemIntrinsic>(II))
824  if (ConstantInt *NumBytes = dyn_cast<ConstantInt>(AMI->getLength()))
825  if (NumBytes->getSExtValue() < 0 ||
826  (NumBytes->getZExtValue() % AMI->getElementSizeInBytes() != 0)) {
827  CreateNonTerminatorUnreachable(AMI);
828  assert(AMI->getType()->isVoidTy() &&
829  "non void atomic unordered mem intrinsic");
830  return eraseInstFromFunction(*AMI);
831  }
832 
833  // Intrinsics cannot occur in an invoke or a callbr, so handle them here
834  // instead of in visitCallBase.
835  if (auto *MI = dyn_cast<AnyMemIntrinsic>(II)) {
836  bool Changed = false;
837 
838  // memmove/cpy/set of zero bytes is a noop.
839  if (Constant *NumBytes = dyn_cast<Constant>(MI->getLength())) {
840  if (NumBytes->isNullValue())
841  return eraseInstFromFunction(CI);
842 
843  if (ConstantInt *CI = dyn_cast<ConstantInt>(NumBytes))
844  if (CI->getZExtValue() == 1) {
845  // Replace the instruction with just byte operations. We would
846  // transform other cases to loads/stores, but we don't know if
847  // alignment is sufficient.
848  }
849  }
850 
851  // No other transformations apply to volatile transfers.
852  if (auto *M = dyn_cast<MemIntrinsic>(MI))
853  if (M->isVolatile())
854  return nullptr;
855 
856  // If we have a memmove and the source operation is a constant global,
857  // then the source and dest pointers can't alias, so we can change this
858  // into a call to memcpy.
859  if (auto *MMI = dyn_cast<AnyMemMoveInst>(MI)) {
860  if (GlobalVariable *GVSrc = dyn_cast<GlobalVariable>(MMI->getSource()))
861  if (GVSrc->isConstant()) {
862  Module *M = CI.getModule();
863  Intrinsic::ID MemCpyID =
864  isa<AtomicMemMoveInst>(MMI)
865  ? Intrinsic::memcpy_element_unordered_atomic
867  Type *Tys[3] = { CI.getArgOperand(0)->getType(),
868  CI.getArgOperand(1)->getType(),
869  CI.getArgOperand(2)->getType() };
870  CI.setCalledFunction(Intrinsic::getDeclaration(M, MemCpyID, Tys));
871  Changed = true;
872  }
873  }
874 
875  if (AnyMemTransferInst *MTI = dyn_cast<AnyMemTransferInst>(MI)) {
876  // memmove(x,x,size) -> noop.
877  if (MTI->getSource() == MTI->getDest())
878  return eraseInstFromFunction(CI);
879  }
880 
881  // If we can determine a pointer alignment that is bigger than currently
882  // set, update the alignment.
883  if (auto *MTI = dyn_cast<AnyMemTransferInst>(MI)) {
884  if (Instruction *I = SimplifyAnyMemTransfer(MTI))
885  return I;
886  } else if (auto *MSI = dyn_cast<AnyMemSetInst>(MI)) {
887  if (Instruction *I = SimplifyAnyMemSet(MSI))
888  return I;
889  }
890 
891  if (Changed) return II;
892  }
893 
894  // For fixed width vector result intrinsics, use the generic demanded vector
895  // support.
896  if (auto *IIFVTy = dyn_cast<FixedVectorType>(II->getType())) {
897  auto VWidth = IIFVTy->getNumElements();
898  APInt UndefElts(VWidth, 0);
899  APInt AllOnesEltMask(APInt::getAllOnesValue(VWidth));
900  if (Value *V = SimplifyDemandedVectorElts(II, AllOnesEltMask, UndefElts)) {
901  if (V != II)
902  return replaceInstUsesWith(*II, V);
903  return II;
904  }
905  }
906 
907  if (II->isCommutative()) {
908  if (CallInst *NewCall = canonicalizeConstantArg0ToArg1(CI))
909  return NewCall;
910  }
911 
912  Intrinsic::ID IID = II->getIntrinsicID();
913  switch (IID) {
914  case Intrinsic::objectsize:
915  if (Value *V = lowerObjectSizeCall(II, DL, &TLI, /*MustSucceed=*/false))
916  return replaceInstUsesWith(CI, V);
917  return nullptr;
918  case Intrinsic::abs: {
919  Value *IIOperand = II->getArgOperand(0);
920  bool IntMinIsPoison = cast<Constant>(II->getArgOperand(1))->isOneValue();
921 
922  // abs(-x) -> abs(x)
923  // TODO: Copy nsw if it was present on the neg?
924  Value *X;
925  if (match(IIOperand, m_Neg(m_Value(X))))
926  return replaceOperand(*II, 0, X);
927  if (match(IIOperand, m_Select(m_Value(), m_Value(X), m_Neg(m_Deferred(X)))))
928  return replaceOperand(*II, 0, X);
929  if (match(IIOperand, m_Select(m_Value(), m_Neg(m_Value(X)), m_Deferred(X))))
930  return replaceOperand(*II, 0, X);
931 
932  if (Optional<bool> Sign = getKnownSign(IIOperand, II, DL, &AC, &DT)) {
933  // abs(x) -> x if x >= 0
934  if (!*Sign)
935  return replaceInstUsesWith(*II, IIOperand);
936 
937  // abs(x) -> -x if x < 0
938  if (IntMinIsPoison)
939  return BinaryOperator::CreateNSWNeg(IIOperand);
940  return BinaryOperator::CreateNeg(IIOperand);
941  }
942 
943  // abs (sext X) --> zext (abs X*)
944  // Clear the IsIntMin (nsw) bit on the abs to allow narrowing.
945  if (match(IIOperand, m_OneUse(m_SExt(m_Value(X))))) {
946  Value *NarrowAbs =
947  Builder.CreateBinaryIntrinsic(Intrinsic::abs, X, Builder.getFalse());
948  return CastInst::Create(Instruction::ZExt, NarrowAbs, II->getType());
949  }
950 
951  // Match a complicated way to check if a number is odd/even:
952  // abs (srem X, 2) --> and X, 1
953  const APInt *C;
954  if (match(IIOperand, m_SRem(m_Value(X), m_APInt(C))) && *C == 2)
955  return BinaryOperator::CreateAnd(X, ConstantInt::get(II->getType(), 1));
956 
957  break;
958  }
959  case Intrinsic::umin: {
960  Value *I0 = II->getArgOperand(0), *I1 = II->getArgOperand(1);
961  // umin(x, 1) == zext(x != 0)
962  if (match(I1, m_One())) {
963  Value *Zero = Constant::getNullValue(I0->getType());
964  Value *Cmp = Builder.CreateICmpNE(I0, Zero);
965  return CastInst::Create(Instruction::ZExt, Cmp, II->getType());
966  }
968  }
969  case Intrinsic::umax: {
970  Value *I0 = II->getArgOperand(0), *I1 = II->getArgOperand(1);
971  Value *X, *Y;
972  if (match(I0, m_ZExt(m_Value(X))) && match(I1, m_ZExt(m_Value(Y))) &&
973  (I0->hasOneUse() || I1->hasOneUse()) && X->getType() == Y->getType()) {
974  Value *NarrowMaxMin = Builder.CreateBinaryIntrinsic(IID, X, Y);
975  return CastInst::Create(Instruction::ZExt, NarrowMaxMin, II->getType());
976  }
977  Constant *C;
978  if (match(I0, m_ZExt(m_Value(X))) && match(I1, m_Constant(C)) &&
979  I0->hasOneUse()) {
980  Constant *NarrowC = ConstantExpr::getTrunc(C, X->getType());
981  if (ConstantExpr::getZExt(NarrowC, II->getType()) == C) {
982  Value *NarrowMaxMin = Builder.CreateBinaryIntrinsic(IID, X, NarrowC);
983  return CastInst::Create(Instruction::ZExt, NarrowMaxMin, II->getType());
984  }
985  }
986  // If both operands of unsigned min/max are sign-extended, it is still ok
987  // to narrow the operation.
989  }
990  case Intrinsic::smax:
991  case Intrinsic::smin: {
992  Value *I0 = II->getArgOperand(0), *I1 = II->getArgOperand(1);
993  Value *X, *Y;
994  if (match(I0, m_SExt(m_Value(X))) && match(I1, m_SExt(m_Value(Y))) &&
995  (I0->hasOneUse() || I1->hasOneUse()) && X->getType() == Y->getType()) {
996  Value *NarrowMaxMin = Builder.CreateBinaryIntrinsic(IID, X, Y);
997  return CastInst::Create(Instruction::SExt, NarrowMaxMin, II->getType());
998  }
999 
1000  Constant *C;
1001  if (match(I0, m_SExt(m_Value(X))) && match(I1, m_Constant(C)) &&
1002  I0->hasOneUse()) {
1003  Constant *NarrowC = ConstantExpr::getTrunc(C, X->getType());
1004  if (ConstantExpr::getSExt(NarrowC, II->getType()) == C) {
1005  Value *NarrowMaxMin = Builder.CreateBinaryIntrinsic(IID, X, NarrowC);
1006  return CastInst::Create(Instruction::SExt, NarrowMaxMin, II->getType());
1007  }
1008  }
1009 
1010  if (match(I0, m_Not(m_Value(X)))) {
1011  // max (not X), (not Y) --> not (min X, Y)
1013  if (match(I1, m_Not(m_Value(Y))) &&
1014  (I0->hasOneUse() || I1->hasOneUse())) {
1015  Value *InvMaxMin = Builder.CreateBinaryIntrinsic(InvID, X, Y);
1016  return BinaryOperator::CreateNot(InvMaxMin);
1017  }
1018  // max (not X), C --> not(min X, ~C)
1019  if (match(I1, m_Constant(C)) && I0->hasOneUse()) {
1020  Constant *NotC = ConstantExpr::getNot(C);
1021  Value *InvMaxMin = Builder.CreateBinaryIntrinsic(InvID, X, NotC);
1022  return BinaryOperator::CreateNot(InvMaxMin);
1023  }
1024  }
1025 
1026  // smax(X, -X) --> abs(X)
1027  // smin(X, -X) --> -abs(X)
1028  // umax(X, -X) --> -abs(X)
1029  // umin(X, -X) --> abs(X)
1030  if (isKnownNegation(I0, I1)) {
1031  // We can choose either operand as the input to abs(), but if we can
1032  // eliminate the only use of a value, that's better for subsequent
1033  // transforms/analysis.
1034  if (I0->hasOneUse() && !I1->hasOneUse())
1035  std::swap(I0, I1);
1036 
1037  // This is some variant of abs(). See if we can propagate 'nsw' to the abs
1038  // operation and potentially its negation.
1039  bool IntMinIsPoison = isKnownNegation(I0, I1, /* NeedNSW */ true);
1040  Value *Abs = Builder.CreateBinaryIntrinsic(
1041  Intrinsic::abs, I0,
1042  ConstantInt::getBool(II->getContext(), IntMinIsPoison));
1043 
1044  // We don't have a "nabs" intrinsic, so negate if needed based on the
1045  // max/min operation.
1046  if (IID == Intrinsic::smin || IID == Intrinsic::umax)
1047  Abs = Builder.CreateNeg(Abs, "nabs", /* NUW */ false, IntMinIsPoison);
1048  return replaceInstUsesWith(CI, Abs);
1049  }
1050 
1051  if (Instruction *Sel = foldClampRangeOfTwo(II, Builder))
1052  return Sel;
1053 
1054  if (match(I1, m_ImmConstant()))
1055  if (auto *Sel = dyn_cast<SelectInst>(I0))
1056  if (Instruction *R = FoldOpIntoSelect(*II, Sel))
1057  return R;
1058 
1059  break;
1060  }
1061  case Intrinsic::bswap: {
1062  Value *IIOperand = II->getArgOperand(0);
1063  Value *X = nullptr;
1064 
1065  // bswap(trunc(bswap(x))) -> trunc(lshr(x, c))
1066  if (match(IIOperand, m_Trunc(m_BSwap(m_Value(X))))) {
1067  unsigned C = X->getType()->getScalarSizeInBits() -
1068  IIOperand->getType()->getScalarSizeInBits();
1069  Value *CV = ConstantInt::get(X->getType(), C);
1070  Value *V = Builder.CreateLShr(X, CV);
1071  return new TruncInst(V, IIOperand->getType());
1072  }
1073  break;
1074  }
1075  case Intrinsic::masked_load:
1076  if (Value *SimplifiedMaskedOp = simplifyMaskedLoad(*II))
1077  return replaceInstUsesWith(CI, SimplifiedMaskedOp);
1078  break;
1079  case Intrinsic::masked_store:
1080  return simplifyMaskedStore(*II);
1081  case Intrinsic::masked_gather:
1082  return simplifyMaskedGather(*II);
1083  case Intrinsic::masked_scatter:
1084  return simplifyMaskedScatter(*II);
1085  case Intrinsic::launder_invariant_group:
1086  case Intrinsic::strip_invariant_group:
1087  if (auto *SkippedBarrier = simplifyInvariantGroupIntrinsic(*II, *this))
1088  return replaceInstUsesWith(*II, SkippedBarrier);
1089  break;
1090  case Intrinsic::powi:
1091  if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
1092  // 0 and 1 are handled in instsimplify
1093  // powi(x, -1) -> 1/x
1094  if (Power->isMinusOne())
1096  II->getArgOperand(0), II);
1097  // powi(x, 2) -> x*x
1098  if (Power->equalsInt(2))
1100  II->getArgOperand(0), II);
1101  }
1102  break;
1103 
1104  case Intrinsic::cttz:
1105  case Intrinsic::ctlz:
1106  if (auto *I = foldCttzCtlz(*II, *this))
1107  return I;
1108  break;
1109 
1110  case Intrinsic::ctpop:
1111  if (auto *I = foldCtpop(*II, *this))
1112  return I;
1113  break;
1114 
1115  case Intrinsic::fshl:
1116  case Intrinsic::fshr: {
1117  Value *Op0 = II->getArgOperand(0), *Op1 = II->getArgOperand(1);
1118  Type *Ty = II->getType();
1119  unsigned BitWidth = Ty->getScalarSizeInBits();
1120  Constant *ShAmtC;
1121  if (match(II->getArgOperand(2), m_ImmConstant(ShAmtC)) &&
1122  !ShAmtC->containsConstantExpression()) {
1123  // Canonicalize a shift amount constant operand to modulo the bit-width.
1124  Constant *WidthC = ConstantInt::get(Ty, BitWidth);
1125  Constant *ModuloC = ConstantExpr::getURem(ShAmtC, WidthC);
1126  if (ModuloC != ShAmtC)
1127  return replaceOperand(*II, 2, ModuloC);
1128 
1129  assert(ConstantExpr::getICmp(ICmpInst::ICMP_UGT, WidthC, ShAmtC) ==
1131  "Shift amount expected to be modulo bitwidth");
1132 
1133  // Canonicalize funnel shift right by constant to funnel shift left. This
1134  // is not entirely arbitrary. For historical reasons, the backend may
1135  // recognize rotate left patterns but miss rotate right patterns.
1136  if (IID == Intrinsic::fshr) {
1137  // fshr X, Y, C --> fshl X, Y, (BitWidth - C)
1138  Constant *LeftShiftC = ConstantExpr::getSub(WidthC, ShAmtC);
1139  Module *Mod = II->getModule();
1140  Function *Fshl = Intrinsic::getDeclaration(Mod, Intrinsic::fshl, Ty);
1141  return CallInst::Create(Fshl, { Op0, Op1, LeftShiftC });
1142  }
1143  assert(IID == Intrinsic::fshl &&
1144  "All funnel shifts by simple constants should go left");
1145 
1146  // fshl(X, 0, C) --> shl X, C
1147  // fshl(X, undef, C) --> shl X, C
1148  if (match(Op1, m_ZeroInt()) || match(Op1, m_Undef()))
1149  return BinaryOperator::CreateShl(Op0, ShAmtC);
1150 
1151  // fshl(0, X, C) --> lshr X, (BW-C)
1152  // fshl(undef, X, C) --> lshr X, (BW-C)
1153  if (match(Op0, m_ZeroInt()) || match(Op0, m_Undef()))
1154  return BinaryOperator::CreateLShr(Op1,
1155  ConstantExpr::getSub(WidthC, ShAmtC));
1156 
1157  // fshl i16 X, X, 8 --> bswap i16 X (reduce to more-specific form)
1158  if (Op0 == Op1 && BitWidth == 16 && match(ShAmtC, m_SpecificInt(8))) {
1159  Module *Mod = II->getModule();
1160  Function *Bswap = Intrinsic::getDeclaration(Mod, Intrinsic::bswap, Ty);
1161  return CallInst::Create(Bswap, { Op0 });
1162  }
1163  }
1164 
1165  // Left or right might be masked.
1166  if (SimplifyDemandedInstructionBits(*II))
1167  return &CI;
1168 
1169  // The shift amount (operand 2) of a funnel shift is modulo the bitwidth,
1170  // so only the low bits of the shift amount are demanded if the bitwidth is
1171  // a power-of-2.
1172  if (!isPowerOf2_32(BitWidth))
1173  break;
1175  KnownBits Op2Known(BitWidth);
1176  if (SimplifyDemandedBits(II, 2, Op2Demanded, Op2Known))
1177  return &CI;
1178  break;
1179  }
1180  case Intrinsic::uadd_with_overflow:
1181  case Intrinsic::sadd_with_overflow: {
1182  if (Instruction *I = foldIntrinsicWithOverflowCommon(II))
1183  return I;
1184 
1185  // Given 2 constant operands whose sum does not overflow:
1186  // uaddo (X +nuw C0), C1 -> uaddo X, C0 + C1
1187  // saddo (X +nsw C0), C1 -> saddo X, C0 + C1
1188  Value *X;
1189  const APInt *C0, *C1;
1190  Value *Arg0 = II->getArgOperand(0);
1191  Value *Arg1 = II->getArgOperand(1);
1192  bool IsSigned = IID == Intrinsic::sadd_with_overflow;
1193  bool HasNWAdd = IsSigned ? match(Arg0, m_NSWAdd(m_Value(X), m_APInt(C0)))
1194  : match(Arg0, m_NUWAdd(m_Value(X), m_APInt(C0)));
1195  if (HasNWAdd && match(Arg1, m_APInt(C1))) {
1196  bool Overflow;
1197  APInt NewC =
1198  IsSigned ? C1->sadd_ov(*C0, Overflow) : C1->uadd_ov(*C0, Overflow);
1199  if (!Overflow)
1200  return replaceInstUsesWith(
1201  *II, Builder.CreateBinaryIntrinsic(
1202  IID, X, ConstantInt::get(Arg1->getType(), NewC)));
1203  }
1204  break;
1205  }
1206 
1207  case Intrinsic::umul_with_overflow:
1208  case Intrinsic::smul_with_overflow:
1209  case Intrinsic::usub_with_overflow:
1210  if (Instruction *I = foldIntrinsicWithOverflowCommon(II))
1211  return I;
1212  break;
1213 
1214  case Intrinsic::ssub_with_overflow: {
1215  if (Instruction *I = foldIntrinsicWithOverflowCommon(II))
1216  return I;
1217 
1218  Constant *C;
1219  Value *Arg0 = II->getArgOperand(0);
1220  Value *Arg1 = II->getArgOperand(1);
1221  // Given a constant C that is not the minimum signed value
1222  // for an integer of a given bit width:
1223  //
1224  // ssubo X, C -> saddo X, -C
1225  if (match(Arg1, m_Constant(C)) && C->isNotMinSignedValue()) {
1226  Value *NegVal = ConstantExpr::getNeg(C);
1227  // Build a saddo call that is equivalent to the discovered
1228  // ssubo call.
1229  return replaceInstUsesWith(
1230  *II, Builder.CreateBinaryIntrinsic(Intrinsic::sadd_with_overflow,
1231  Arg0, NegVal));
1232  }
1233 
1234  break;
1235  }
1236 
1237  case Intrinsic::uadd_sat:
1238  case Intrinsic::sadd_sat:
1239  case Intrinsic::usub_sat:
1240  case Intrinsic::ssub_sat: {
1241  SaturatingInst *SI = cast<SaturatingInst>(II);
1242  Type *Ty = SI->getType();
1243  Value *Arg0 = SI->getLHS();
1244  Value *Arg1 = SI->getRHS();
1245 
1246  // Make use of known overflow information.
1247  OverflowResult OR = computeOverflow(SI->getBinaryOp(), SI->isSigned(),
1248  Arg0, Arg1, SI);
1249  switch (OR) {
1251  break;
1253  if (SI->isSigned())
1254  return BinaryOperator::CreateNSW(SI->getBinaryOp(), Arg0, Arg1);
1255  else
1256  return BinaryOperator::CreateNUW(SI->getBinaryOp(), Arg0, Arg1);
1258  unsigned BitWidth = Ty->getScalarSizeInBits();
1259  APInt Min = APSInt::getMinValue(BitWidth, !SI->isSigned());
1260  return replaceInstUsesWith(*SI, ConstantInt::get(Ty, Min));
1261  }
1263  unsigned BitWidth = Ty->getScalarSizeInBits();
1264  APInt Max = APSInt::getMaxValue(BitWidth, !SI->isSigned());
1265  return replaceInstUsesWith(*SI, ConstantInt::get(Ty, Max));
1266  }
1267  }
1268 
1269  // ssub.sat(X, C) -> sadd.sat(X, -C) if C != MIN
1270  Constant *C;
1271  if (IID == Intrinsic::ssub_sat && match(Arg1, m_Constant(C)) &&
1272  C->isNotMinSignedValue()) {
1273  Value *NegVal = ConstantExpr::getNeg(C);
1274  return replaceInstUsesWith(
1275  *II, Builder.CreateBinaryIntrinsic(
1276  Intrinsic::sadd_sat, Arg0, NegVal));
1277  }
1278 
1279  // sat(sat(X + Val2) + Val) -> sat(X + (Val+Val2))
1280  // sat(sat(X - Val2) - Val) -> sat(X - (Val+Val2))
1281  // if Val and Val2 have the same sign
1282  if (auto *Other = dyn_cast<IntrinsicInst>(Arg0)) {
1283  Value *X;
1284  const APInt *Val, *Val2;
1285  APInt NewVal;
1286  bool IsUnsigned =
1287  IID == Intrinsic::uadd_sat || IID == Intrinsic::usub_sat;
1288  if (Other->getIntrinsicID() == IID &&
1289  match(Arg1, m_APInt(Val)) &&
1290  match(Other->getArgOperand(0), m_Value(X)) &&
1291  match(Other->getArgOperand(1), m_APInt(Val2))) {
1292  if (IsUnsigned)
1293  NewVal = Val->uadd_sat(*Val2);
1294  else if (Val->isNonNegative() == Val2->isNonNegative()) {
1295  bool Overflow;
1296  NewVal = Val->sadd_ov(*Val2, Overflow);
1297  if (Overflow) {
1298  // Both adds together may add more than SignedMaxValue
1299  // without saturating the final result.
1300  break;
1301  }
1302  } else {
1303  // Cannot fold saturated addition with different signs.
1304  break;
1305  }
1306 
1307  return replaceInstUsesWith(
1308  *II, Builder.CreateBinaryIntrinsic(
1309  IID, X, ConstantInt::get(II->getType(), NewVal)));
1310  }
1311  }
1312  break;
1313  }
1314 
1315  case Intrinsic::minnum:
1316  case Intrinsic::maxnum:
1317  case Intrinsic::minimum:
1318  case Intrinsic::maximum: {
1319  Value *Arg0 = II->getArgOperand(0);
1320  Value *Arg1 = II->getArgOperand(1);
1321  Value *X, *Y;
1322  if (match(Arg0, m_FNeg(m_Value(X))) && match(Arg1, m_FNeg(m_Value(Y))) &&
1323  (Arg0->hasOneUse() || Arg1->hasOneUse())) {
1324  // If both operands are negated, invert the call and negate the result:
1325  // min(-X, -Y) --> -(max(X, Y))
1326  // max(-X, -Y) --> -(min(X, Y))
1327  Intrinsic::ID NewIID;
1328  switch (IID) {
1329  case Intrinsic::maxnum:
1330  NewIID = Intrinsic::minnum;
1331  break;
1332  case Intrinsic::minnum:
1333  NewIID = Intrinsic::maxnum;
1334  break;
1335  case Intrinsic::maximum:
1336  NewIID = Intrinsic::minimum;
1337  break;
1338  case Intrinsic::minimum:
1339  NewIID = Intrinsic::maximum;
1340  break;
1341  default:
1342  llvm_unreachable("unexpected intrinsic ID");
1343  }
1344  Value *NewCall = Builder.CreateBinaryIntrinsic(NewIID, X, Y, II);
1345  Instruction *FNeg = UnaryOperator::CreateFNeg(NewCall);
1346  FNeg->copyIRFlags(II);
1347  return FNeg;
1348  }
1349 
1350  // m(m(X, C2), C1) -> m(X, C)
1351  const APFloat *C1, *C2;
1352  if (auto *M = dyn_cast<IntrinsicInst>(Arg0)) {
1353  if (M->getIntrinsicID() == IID && match(Arg1, m_APFloat(C1)) &&
1354  ((match(M->getArgOperand(0), m_Value(X)) &&
1355  match(M->getArgOperand(1), m_APFloat(C2))) ||
1356  (match(M->getArgOperand(1), m_Value(X)) &&
1357  match(M->getArgOperand(0), m_APFloat(C2))))) {
1358  APFloat Res(0.0);
1359  switch (IID) {
1360  case Intrinsic::maxnum:
1361  Res = maxnum(*C1, *C2);
1362  break;
1363  case Intrinsic::minnum:
1364  Res = minnum(*C1, *C2);
1365  break;
1366  case Intrinsic::maximum:
1367  Res = maximum(*C1, *C2);
1368  break;
1369  case Intrinsic::minimum:
1370  Res = minimum(*C1, *C2);
1371  break;
1372  default:
1373  llvm_unreachable("unexpected intrinsic ID");
1374  }
1375  Instruction *NewCall = Builder.CreateBinaryIntrinsic(
1376  IID, X, ConstantFP::get(Arg0->getType(), Res), II);
1377  // TODO: Conservatively intersecting FMF. If Res == C2, the transform
1378  // was a simplification (so Arg0 and its original flags could
1379  // propagate?)
1380  NewCall->andIRFlags(M);
1381  return replaceInstUsesWith(*II, NewCall);
1382  }
1383  }
1384 
1385  // m((fpext X), (fpext Y)) -> fpext (m(X, Y))
1386  if (match(Arg0, m_OneUse(m_FPExt(m_Value(X)))) &&
1387  match(Arg1, m_OneUse(m_FPExt(m_Value(Y)))) &&
1388  X->getType() == Y->getType()) {
1389  Value *NewCall =
1390  Builder.CreateBinaryIntrinsic(IID, X, Y, II, II->getName());
1391  return new FPExtInst(NewCall, II->getType());
1392  }
1393 
1394  // max X, -X --> fabs X
1395  // min X, -X --> -(fabs X)
1396  // TODO: Remove one-use limitation? That is obviously better for max.
1397  // It would be an extra instruction for min (fnabs), but that is
1398  // still likely better for analysis and codegen.
1399  if ((match(Arg0, m_OneUse(m_FNeg(m_Value(X)))) && Arg1 == X) ||
1400  (match(Arg1, m_OneUse(m_FNeg(m_Value(X)))) && Arg0 == X)) {
1401  Value *R = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X, II);
1402  if (IID == Intrinsic::minimum || IID == Intrinsic::minnum)
1403  R = Builder.CreateFNegFMF(R, II);
1404  return replaceInstUsesWith(*II, R);
1405  }
1406 
1407  break;
1408  }
1409  case Intrinsic::fmuladd: {
1410  // Canonicalize fast fmuladd to the separate fmul + fadd.
1411  if (II->isFast()) {
1413  Builder.setFastMathFlags(II->getFastMathFlags());
1414  Value *Mul = Builder.CreateFMul(II->getArgOperand(0),
1415  II->getArgOperand(1));
1416  Value *Add = Builder.CreateFAdd(Mul, II->getArgOperand(2));
1417  Add->takeName(II);
1418  return replaceInstUsesWith(*II, Add);
1419  }
1420 
1421  // Try to simplify the underlying FMul.
1422  if (Value *V = SimplifyFMulInst(II->getArgOperand(0), II->getArgOperand(1),
1423  II->getFastMathFlags(),
1424  SQ.getWithInstruction(II))) {
1425  auto *FAdd = BinaryOperator::CreateFAdd(V, II->getArgOperand(2));
1426  FAdd->copyFastMathFlags(II);
1427  return FAdd;
1428  }
1429 
1431  }
1432  case Intrinsic::fma: {
1433  // fma fneg(x), fneg(y), z -> fma x, y, z
1434  Value *Src0 = II->getArgOperand(0);
1435  Value *Src1 = II->getArgOperand(1);
1436  Value *X, *Y;
1437  if (match(Src0, m_FNeg(m_Value(X))) && match(Src1, m_FNeg(m_Value(Y)))) {
1438  replaceOperand(*II, 0, X);
1439  replaceOperand(*II, 1, Y);
1440  return II;
1441  }
1442 
1443  // fma fabs(x), fabs(x), z -> fma x, x, z
1444  if (match(Src0, m_FAbs(m_Value(X))) &&
1445  match(Src1, m_FAbs(m_Specific(X)))) {
1446  replaceOperand(*II, 0, X);
1447  replaceOperand(*II, 1, X);
1448  return II;
1449  }
1450 
1451  // Try to simplify the underlying FMul. We can only apply simplifications
1452  // that do not require rounding.
1453  if (Value *V = SimplifyFMAFMul(II->getArgOperand(0), II->getArgOperand(1),
1454  II->getFastMathFlags(),
1455  SQ.getWithInstruction(II))) {
1456  auto *FAdd = BinaryOperator::CreateFAdd(V, II->getArgOperand(2));
1457  FAdd->copyFastMathFlags(II);
1458  return FAdd;
1459  }
1460 
1461  // fma x, y, 0 -> fmul x, y
1462  // This is always valid for -0.0, but requires nsz for +0.0 as
1463  // -0.0 + 0.0 = 0.0, which would not be the same as the fmul on its own.
1464  if (match(II->getArgOperand(2), m_NegZeroFP()) ||
1465  (match(II->getArgOperand(2), m_PosZeroFP()) &&
1467  return BinaryOperator::CreateFMulFMF(Src0, Src1, II);
1468 
1469  break;
1470  }
1471  case Intrinsic::copysign: {
1472  Value *Mag = II->getArgOperand(0), *Sign = II->getArgOperand(1);
1473  if (SignBitMustBeZero(Sign, &TLI)) {
1474  // If we know that the sign argument is positive, reduce to FABS:
1475  // copysign Mag, +Sign --> fabs Mag
1476  Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);
1477  return replaceInstUsesWith(*II, Fabs);
1478  }
1479  // TODO: There should be a ValueTracking sibling like SignBitMustBeOne.
1480  const APFloat *C;
1481  if (match(Sign, m_APFloat(C)) && C->isNegative()) {
1482  // If we know that the sign argument is negative, reduce to FNABS:
1483  // copysign Mag, -Sign --> fneg (fabs Mag)
1484  Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);
1485  return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));
1486  }
1487 
1488  // Propagate sign argument through nested calls:
1489  // copysign Mag, (copysign ?, X) --> copysign Mag, X
1490  Value *X;
1491  if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X))))
1492  return replaceOperand(*II, 1, X);
1493 
1494  // Peek through changes of magnitude's sign-bit. This call rewrites those:
1495  // copysign (fabs X), Sign --> copysign X, Sign
1496  // copysign (fneg X), Sign --> copysign X, Sign
1497  if (match(Mag, m_FAbs(m_Value(X))) || match(Mag, m_FNeg(m_Value(X))))
1498  return replaceOperand(*II, 0, X);
1499 
1500  break;
1501  }
1502  case Intrinsic::fabs: {
1503  Value *Cond, *TVal, *FVal;
1504  if (match(II->getArgOperand(0),
1505  m_Select(m_Value(Cond), m_Value(TVal), m_Value(FVal)))) {
1506  // fabs (select Cond, TrueC, FalseC) --> select Cond, AbsT, AbsF
1507  if (isa<Constant>(TVal) && isa<Constant>(FVal)) {
1508  CallInst *AbsT = Builder.CreateCall(II->getCalledFunction(), {TVal});
1509  CallInst *AbsF = Builder.CreateCall(II->getCalledFunction(), {FVal});
1510  return SelectInst::Create(Cond, AbsT, AbsF);
1511  }
1512  // fabs (select Cond, -FVal, FVal) --> fabs FVal
1513  if (match(TVal, m_FNeg(m_Specific(FVal))))
1514  return replaceOperand(*II, 0, FVal);
1515  // fabs (select Cond, TVal, -TVal) --> fabs TVal
1516  if (match(FVal, m_FNeg(m_Specific(TVal))))
1517  return replaceOperand(*II, 0, TVal);
1518  }
1519 
1521  }
1522  case Intrinsic::ceil:
1523  case Intrinsic::floor:
1524  case Intrinsic::round:
1525  case Intrinsic::roundeven:
1526  case Intrinsic::nearbyint:
1527  case Intrinsic::rint:
1528  case Intrinsic::trunc: {
1529  Value *ExtSrc;
1530  if (match(II->getArgOperand(0), m_OneUse(m_FPExt(m_Value(ExtSrc))))) {
1531  // Narrow the call: intrinsic (fpext x) -> fpext (intrinsic x)
1532  Value *NarrowII = Builder.CreateUnaryIntrinsic(IID, ExtSrc, II);
1533  return new FPExtInst(NarrowII, II->getType());
1534  }
1535  break;
1536  }
1537  case Intrinsic::cos:
1538  case Intrinsic::amdgcn_cos: {
1539  Value *X;
1540  Value *Src = II->getArgOperand(0);
1541  if (match(Src, m_FNeg(m_Value(X))) || match(Src, m_FAbs(m_Value(X)))) {
1542  // cos(-x) -> cos(x)
1543  // cos(fabs(x)) -> cos(x)
1544  return replaceOperand(*II, 0, X);
1545  }
1546  break;
1547  }
1548  case Intrinsic::sin: {
1549  Value *X;
1550  if (match(II->getArgOperand(0), m_OneUse(m_FNeg(m_Value(X))))) {
1551  // sin(-x) --> -sin(x)
1552  Value *NewSin = Builder.CreateUnaryIntrinsic(Intrinsic::sin, X, II);
1553  Instruction *FNeg = UnaryOperator::CreateFNeg(NewSin);
1554  FNeg->copyFastMathFlags(II);
1555  return FNeg;
1556  }
1557  break;
1558  }
1559 
1560  case Intrinsic::arm_neon_vtbl1:
1561  case Intrinsic::aarch64_neon_tbl1:
1562  if (Value *V = simplifyNeonTbl1(*II, Builder))
1563  return replaceInstUsesWith(*II, V);
1564  break;
1565 
1566  case Intrinsic::arm_neon_vmulls:
1567  case Intrinsic::arm_neon_vmullu:
1568  case Intrinsic::aarch64_neon_smull:
1569  case Intrinsic::aarch64_neon_umull: {
1570  Value *Arg0 = II->getArgOperand(0);
1571  Value *Arg1 = II->getArgOperand(1);
1572 
1573  // Handle mul by zero first:
1574  if (isa<ConstantAggregateZero>(Arg0) || isa<ConstantAggregateZero>(Arg1)) {
1575  return replaceInstUsesWith(CI, ConstantAggregateZero::get(II->getType()));
1576  }
1577 
1578  // Check for constant LHS & RHS - in this case we just simplify.
1579  bool Zext = (IID == Intrinsic::arm_neon_vmullu ||
1580  IID == Intrinsic::aarch64_neon_umull);
1581  VectorType *NewVT = cast<VectorType>(II->getType());
1582  if (Constant *CV0 = dyn_cast<Constant>(Arg0)) {
1583  if (Constant *CV1 = dyn_cast<Constant>(Arg1)) {
1584  CV0 = ConstantExpr::getIntegerCast(CV0, NewVT, /*isSigned=*/!Zext);
1585  CV1 = ConstantExpr::getIntegerCast(CV1, NewVT, /*isSigned=*/!Zext);
1586 
1587  return replaceInstUsesWith(CI, ConstantExpr::getMul(CV0, CV1));
1588  }
1589 
1590  // Couldn't simplify - canonicalize constant to the RHS.
1591  std::swap(Arg0, Arg1);
1592  }
1593 
1594  // Handle mul by one:
1595  if (Constant *CV1 = dyn_cast<Constant>(Arg1))
1596  if (ConstantInt *Splat =
1597  dyn_cast_or_null<ConstantInt>(CV1->getSplatValue()))
1598  if (Splat->isOne())
1599  return CastInst::CreateIntegerCast(Arg0, II->getType(),
1600  /*isSigned=*/!Zext);
1601 
1602  break;
1603  }
1604  case Intrinsic::arm_neon_aesd:
1605  case Intrinsic::arm_neon_aese:
1606  case Intrinsic::aarch64_crypto_aesd:
1607  case Intrinsic::aarch64_crypto_aese: {
1608  Value *DataArg = II->getArgOperand(0);
1609  Value *KeyArg = II->getArgOperand(1);
1610 
1611  // Try to use the builtin XOR in AESE and AESD to eliminate a prior XOR
1612  Value *Data, *Key;
1613  if (match(KeyArg, m_ZeroInt()) &&
1614  match(DataArg, m_Xor(m_Value(Data), m_Value(Key)))) {
1615  replaceOperand(*II, 0, Data);
1616  replaceOperand(*II, 1, Key);
1617  return II;
1618  }
1619  break;
1620  }
1621  case Intrinsic::hexagon_V6_vandvrt:
1622  case Intrinsic::hexagon_V6_vandvrt_128B: {
1623  // Simplify Q -> V -> Q conversion.
1624  if (auto Op0 = dyn_cast<IntrinsicInst>(II->getArgOperand(0))) {
1625  Intrinsic::ID ID0 = Op0->getIntrinsicID();
1626  if (ID0 != Intrinsic::hexagon_V6_vandqrt &&
1627  ID0 != Intrinsic::hexagon_V6_vandqrt_128B)
1628  break;
1629  Value *Bytes = Op0->getArgOperand(1), *Mask = II->getArgOperand(1);
1630  uint64_t Bytes1 = computeKnownBits(Bytes, 0, Op0).One.getZExtValue();
1631  uint64_t Mask1 = computeKnownBits(Mask, 0, II).One.getZExtValue();
1632  // Check if every byte has common bits in Bytes and Mask.
1633  uint64_t C = Bytes1 & Mask1;
1634  if ((C & 0xFF) && (C & 0xFF00) && (C & 0xFF0000) && (C & 0xFF000000))
1635  return replaceInstUsesWith(*II, Op0->getArgOperand(0));
1636  }
1637  break;
1638  }
1639  case Intrinsic::stackrestore: {
1640  // If the save is right next to the restore, remove the restore. This can
1641  // happen when variable allocas are DCE'd.
1642  if (IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getArgOperand(0))) {
1643  if (SS->getIntrinsicID() == Intrinsic::stacksave) {
1644  // Skip over debug info.
1645  if (SS->getNextNonDebugInstruction() == II) {
1646  return eraseInstFromFunction(CI);
1647  }
1648  }
1649  }
1650 
1651  // Scan down this block to see if there is another stack restore in the
1652  // same block without an intervening call/alloca.
1653  BasicBlock::iterator BI(II);
1654  Instruction *TI = II->getParent()->getTerminator();
1655  bool CannotRemove = false;
1656  for (++BI; &*BI != TI; ++BI) {
1657  if (isa<AllocaInst>(BI)) {
1658  CannotRemove = true;
1659  break;
1660  }
1661  if (CallInst *BCI = dyn_cast<CallInst>(BI)) {
1662  if (auto *II2 = dyn_cast<IntrinsicInst>(BCI)) {
1663  // If there is a stackrestore below this one, remove this one.
1664  if (II2->getIntrinsicID() == Intrinsic::stackrestore)
1665  return eraseInstFromFunction(CI);
1666 
1667  // Bail if we cross over an intrinsic with side effects, such as
1668  // llvm.stacksave, or llvm.read_register.
1669  if (II2->mayHaveSideEffects()) {
1670  CannotRemove = true;
1671  break;
1672  }
1673  } else {
1674  // If we found a non-intrinsic call, we can't remove the stack
1675  // restore.
1676  CannotRemove = true;
1677  break;
1678  }
1679  }
1680  }
1681 
1682  // If the stack restore is in a return, resume, or unwind block and if there
1683  // are no allocas or calls between the restore and the return, nuke the
1684  // restore.
1685  if (!CannotRemove && (isa<ReturnInst>(TI) || isa<ResumeInst>(TI)))
1686  return eraseInstFromFunction(CI);
1687  break;
1688  }
1689  case Intrinsic::lifetime_end:
1690  // Asan needs to poison memory to detect invalid access which is possible
1691  // even for empty lifetime range.
1692  if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
1693  II->getFunction()->hasFnAttribute(Attribute::SanitizeMemory) ||
1694  II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
1695  break;
1696 
1697  if (removeTriviallyEmptyRange(*II, *this, [](const IntrinsicInst &I) {
1698  return I.getIntrinsicID() == Intrinsic::lifetime_start;
1699  }))
1700  return nullptr;
1701  break;
1702  case Intrinsic::assume: {
1703  Value *IIOperand = II->getArgOperand(0);
1705  II->getOperandBundlesAsDefs(OpBundles);
1706 
1707  /// This will remove the boolean Condition from the assume given as
1708  /// argument and remove the assume if it becomes useless.
1709  /// always returns nullptr for use as a return values.
1710  auto RemoveConditionFromAssume = [&](Instruction *Assume) -> Instruction * {
1711  assert(isa<AssumeInst>(Assume));
1712  if (isAssumeWithEmptyBundle(*cast<AssumeInst>(II)))
1713  return eraseInstFromFunction(CI);
1714  replaceUse(II->getOperandUse(0), ConstantInt::getTrue(II->getContext()));
1715  return nullptr;
1716  };
1717  // Remove an assume if it is followed by an identical assume.
1718  // TODO: Do we need this? Unless there are conflicting assumptions, the
1719  // computeKnownBits(IIOperand) below here eliminates redundant assumes.
1721  if (match(Next, m_Intrinsic<Intrinsic::assume>(m_Specific(IIOperand))))
1722  return RemoveConditionFromAssume(Next);
1723 
1724  // Canonicalize assume(a && b) -> assume(a); assume(b);
1725  // Note: New assumption intrinsics created here are registered by
1726  // the InstCombineIRInserter object.
1727  FunctionType *AssumeIntrinsicTy = II->getFunctionType();
1728  Value *AssumeIntrinsic = II->getCalledOperand();
1729  Value *A, *B;
1730  if (match(IIOperand, m_LogicalAnd(m_Value(A), m_Value(B)))) {
1731  Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, A, OpBundles,
1732  II->getName());
1733  Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, B, II->getName());
1734  return eraseInstFromFunction(*II);
1735  }
1736  // assume(!(a || b)) -> assume(!a); assume(!b);
1737  if (match(IIOperand, m_Not(m_LogicalOr(m_Value(A), m_Value(B))))) {
1738  Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic,
1739  Builder.CreateNot(A), OpBundles, II->getName());
1740  Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic,
1741  Builder.CreateNot(B), II->getName());
1742  return eraseInstFromFunction(*II);
1743  }
1744 
1745  // assume( (load addr) != null ) -> add 'nonnull' metadata to load
1746  // (if assume is valid at the load)
1747  CmpInst::Predicate Pred;
1748  Instruction *LHS;
1749  if (match(IIOperand, m_ICmp(Pred, m_Instruction(LHS), m_Zero())) &&
1750  Pred == ICmpInst::ICMP_NE && LHS->getOpcode() == Instruction::Load &&
1751  LHS->getType()->isPointerTy() &&
1752  isValidAssumeForContext(II, LHS, &DT)) {
1753  MDNode *MD = MDNode::get(II->getContext(), None);
1754  LHS->setMetadata(LLVMContext::MD_nonnull, MD);
1755  return RemoveConditionFromAssume(II);
1756 
1757  // TODO: apply nonnull return attributes to calls and invokes
1758  // TODO: apply range metadata for range check patterns?
1759  }
1760 
1761  // Convert nonnull assume like:
1762  // %A = icmp ne i32* %PTR, null
1763  // call void @llvm.assume(i1 %A)
1764  // into
1765  // call void @llvm.assume(i1 true) [ "nonnull"(i32* %PTR) ]
1767  match(IIOperand, m_Cmp(Pred, m_Value(A), m_Zero())) &&
1768  Pred == CmpInst::ICMP_NE && A->getType()->isPointerTy()) {
1769  if (auto *Replacement = buildAssumeFromKnowledge(
1770  {RetainedKnowledge{Attribute::NonNull, 0, A}}, Next, &AC, &DT)) {
1771 
1772  Replacement->insertBefore(Next);
1773  AC.registerAssumption(Replacement);
1774  return RemoveConditionFromAssume(II);
1775  }
1776  }
1777 
1778  // Convert alignment assume like:
1779  // %B = ptrtoint i32* %A to i64
1780  // %C = and i64 %B, Constant
1781  // %D = icmp eq i64 %C, 0
1782  // call void @llvm.assume(i1 %D)
1783  // into
1784  // call void @llvm.assume(i1 true) [ "align"(i32* [[A]], i64 Constant + 1)]
1785  uint64_t AlignMask;
1787  match(IIOperand,
1788  m_Cmp(Pred, m_And(m_Value(A), m_ConstantInt(AlignMask)),
1789  m_Zero())) &&
1790  Pred == CmpInst::ICMP_EQ) {
1791  if (isPowerOf2_64(AlignMask + 1)) {
1792  uint64_t Offset = 0;
1794  if (match(A, m_PtrToInt(m_Value(A)))) {
1795  /// Note: this doesn't preserve the offset information but merges
1796  /// offset and alignment.
1797  /// TODO: we can generate a GEP instead of merging the alignment with
1798  /// the offset.
1799  RetainedKnowledge RK{Attribute::Alignment,
1800  (unsigned)MinAlign(Offset, AlignMask + 1), A};
1801  if (auto *Replacement =
1802  buildAssumeFromKnowledge(RK, Next, &AC, &DT)) {
1803 
1804  Replacement->insertAfter(II);
1805  AC.registerAssumption(Replacement);
1806  }
1807  return RemoveConditionFromAssume(II);
1808  }
1809  }
1810  }
1811 
1812  /// Canonicalize Knowledge in operand bundles.
1814  for (unsigned Idx = 0; Idx < II->getNumOperandBundles(); Idx++) {
1815  auto &BOI = II->bundle_op_info_begin()[Idx];
1816  RetainedKnowledge RK =
1817  llvm::getKnowledgeFromBundle(cast<AssumeInst>(*II), BOI);
1818  if (BOI.End - BOI.Begin > 2)
1819  continue; // Prevent reducing knowledge in an align with offset since
1820  // extracting a RetainedKnowledge form them looses offset
1821  // information
1822  RetainedKnowledge CanonRK =
1823  llvm::simplifyRetainedKnowledge(cast<AssumeInst>(II), RK,
1824  &getAssumptionCache(),
1825  &getDominatorTree());
1826  if (CanonRK == RK)
1827  continue;
1828  if (!CanonRK) {
1829  if (BOI.End - BOI.Begin > 0) {
1830  Worklist.pushValue(II->op_begin()[BOI.Begin]);
1831  Value::dropDroppableUse(II->op_begin()[BOI.Begin]);
1832  }
1833  continue;
1834  }
1835  assert(RK.AttrKind == CanonRK.AttrKind);
1836  if (BOI.End - BOI.Begin > 0)
1837  II->op_begin()[BOI.Begin].set(CanonRK.WasOn);
1838  if (BOI.End - BOI.Begin > 1)
1839  II->op_begin()[BOI.Begin + 1].set(ConstantInt::get(
1840  Type::getInt64Ty(II->getContext()), CanonRK.ArgValue));
1841  if (RK.WasOn)
1842  Worklist.pushValue(RK.WasOn);
1843  return II;
1844  }
1845  }
1846 
1847  // If there is a dominating assume with the same condition as this one,
1848  // then this one is redundant, and should be removed.
1849  KnownBits Known(1);
1850  computeKnownBits(IIOperand, Known, 0, II);
1851  if (Known.isAllOnes() && isAssumeWithEmptyBundle(cast<AssumeInst>(*II)))
1852  return eraseInstFromFunction(*II);
1853 
1854  // Update the cache of affected values for this assumption (we might be
1855  // here because we just simplified the condition).
1856  AC.updateAffectedValues(cast<AssumeInst>(II));
1857  break;
1858  }
1859  case Intrinsic::experimental_guard: {
1860  // Is this guard followed by another guard? We scan forward over a small
1861  // fixed window of instructions to handle common cases with conditions
1862  // computed between guards.
1863  Instruction *NextInst = II->getNextNonDebugInstruction();
1864  for (unsigned i = 0; i < GuardWideningWindow; i++) {
1865  // Note: Using context-free form to avoid compile time blow up
1866  if (!isSafeToSpeculativelyExecute(NextInst))
1867  break;
1868  NextInst = NextInst->getNextNonDebugInstruction();
1869  }
1870  Value *NextCond = nullptr;
1871  if (match(NextInst,
1872  m_Intrinsic<Intrinsic::experimental_guard>(m_Value(NextCond)))) {
1873  Value *CurrCond = II->getArgOperand(0);
1874 
1875  // Remove a guard that it is immediately preceded by an identical guard.
1876  // Otherwise canonicalize guard(a); guard(b) -> guard(a & b).
1877  if (CurrCond != NextCond) {
1878  Instruction *MoveI = II->getNextNonDebugInstruction();
1879  while (MoveI != NextInst) {
1880  auto *Temp = MoveI;
1881  MoveI = MoveI->getNextNonDebugInstruction();
1882  Temp->moveBefore(II);
1883  }
1884  replaceOperand(*II, 0, Builder.CreateAnd(CurrCond, NextCond));
1885  }
1886  eraseInstFromFunction(*NextInst);
1887  return II;
1888  }
1889  break;
1890  }
1891  case Intrinsic::experimental_vector_insert: {
1892  Value *Vec = II->getArgOperand(0);
1893  Value *SubVec = II->getArgOperand(1);
1894  Value *Idx = II->getArgOperand(2);
1895  auto *DstTy = dyn_cast<FixedVectorType>(II->getType());
1896  auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType());
1897  auto *SubVecTy = dyn_cast<FixedVectorType>(SubVec->getType());
1898 
1899  // Only canonicalize if the destination vector, Vec, and SubVec are all
1900  // fixed vectors.
1901  if (DstTy && VecTy && SubVecTy) {
1902  unsigned DstNumElts = DstTy->getNumElements();
1903  unsigned VecNumElts = VecTy->getNumElements();
1904  unsigned SubVecNumElts = SubVecTy->getNumElements();
1905  unsigned IdxN = cast<ConstantInt>(Idx)->getZExtValue();
1906 
1907  // An insert that entirely overwrites Vec with SubVec is a nop.
1908  if (VecNumElts == SubVecNumElts)
1909  return replaceInstUsesWith(CI, SubVec);
1910 
1911  // Widen SubVec into a vector of the same width as Vec, since
1912  // shufflevector requires the two input vectors to be the same width.
1913  // Elements beyond the bounds of SubVec within the widened vector are
1914  // undefined.
1915  SmallVector<int, 8> WidenMask;
1916  unsigned i;
1917  for (i = 0; i != SubVecNumElts; ++i)
1918  WidenMask.push_back(i);
1919  for (; i != VecNumElts; ++i)
1920  WidenMask.push_back(UndefMaskElem);
1921 
1922  Value *WidenShuffle = Builder.CreateShuffleVector(SubVec, WidenMask);
1923 
1925  for (unsigned i = 0; i != IdxN; ++i)
1926  Mask.push_back(i);
1927  for (unsigned i = DstNumElts; i != DstNumElts + SubVecNumElts; ++i)
1928  Mask.push_back(i);
1929  for (unsigned i = IdxN + SubVecNumElts; i != DstNumElts; ++i)
1930  Mask.push_back(i);
1931 
1932  Value *Shuffle = Builder.CreateShuffleVector(Vec, WidenShuffle, Mask);
1933  return replaceInstUsesWith(CI, Shuffle);
1934  }
1935  break;
1936  }
1937  case Intrinsic::experimental_vector_extract: {
1938  Value *Vec = II->getArgOperand(0);
1939  Value *Idx = II->getArgOperand(1);
1940 
1941  auto *DstTy = dyn_cast<FixedVectorType>(II->getType());
1942  auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType());
1943 
1944  // Only canonicalize if the the destination vector and Vec are fixed
1945  // vectors.
1946  if (DstTy && VecTy) {
1947  unsigned DstNumElts = DstTy->getNumElements();
1948  unsigned VecNumElts = VecTy->getNumElements();
1949  unsigned IdxN = cast<ConstantInt>(Idx)->getZExtValue();
1950 
1951  // Extracting the entirety of Vec is a nop.
1952  if (VecNumElts == DstNumElts) {
1953  replaceInstUsesWith(CI, Vec);
1954  return eraseInstFromFunction(CI);
1955  }
1956 
1958  for (unsigned i = 0; i != DstNumElts; ++i)
1959  Mask.push_back(IdxN + i);
1960 
1961  Value *Shuffle = Builder.CreateShuffleVector(Vec, Mask);
1962  return replaceInstUsesWith(CI, Shuffle);
1963  }
1964  break;
1965  }
1966  case Intrinsic::vector_reduce_or:
1967  case Intrinsic::vector_reduce_and: {
1968  // Canonicalize logical or/and reductions:
1969  // Or reduction for i1 is represented as:
1970  // %val = bitcast <ReduxWidth x i1> to iReduxWidth
1971  // %res = cmp ne iReduxWidth %val, 0
1972  // And reduction for i1 is represented as:
1973  // %val = bitcast <ReduxWidth x i1> to iReduxWidth
1974  // %res = cmp eq iReduxWidth %val, 11111
1975  Value *Arg = II->getArgOperand(0);
1976  Value *Vect;
1977  if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
1978  if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
1979  if (FTy->getElementType() == Builder.getInt1Ty()) {
1980  Value *Res = Builder.CreateBitCast(
1981  Vect, Builder.getIntNTy(FTy->getNumElements()));
1982  if (IID == Intrinsic::vector_reduce_and) {
1983  Res = Builder.CreateICmpEQ(
1984  Res, ConstantInt::getAllOnesValue(Res->getType()));
1985  } else {
1986  assert(IID == Intrinsic::vector_reduce_or &&
1987  "Expected or reduction.");
1988  Res = Builder.CreateIsNotNull(Res);
1989  }
1990  if (Arg != Vect)
1991  Res = Builder.CreateCast(cast<CastInst>(Arg)->getOpcode(), Res,
1992  II->getType());
1993  return replaceInstUsesWith(CI, Res);
1994  }
1995  }
1997  }
1998  case Intrinsic::vector_reduce_add: {
1999  if (IID == Intrinsic::vector_reduce_add) {
2000  // Convert vector_reduce_add(ZExt(<n x i1>)) to
2001  // ZExtOrTrunc(ctpop(bitcast <n x i1> to in)).
2002  // Convert vector_reduce_add(SExt(<n x i1>)) to
2003  // -ZExtOrTrunc(ctpop(bitcast <n x i1> to in)).
2004  // Convert vector_reduce_add(<n x i1>) to
2005  // Trunc(ctpop(bitcast <n x i1> to in)).
2006  Value *Arg = II->getArgOperand(0);
2007  Value *Vect;
2008  if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
2009  if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
2010  if (FTy->getElementType() == Builder.getInt1Ty()) {
2011  Value *V = Builder.CreateBitCast(
2012  Vect, Builder.getIntNTy(FTy->getNumElements()));
2013  Value *Res = Builder.CreateUnaryIntrinsic(Intrinsic::ctpop, V);
2014  if (Res->getType() != II->getType())
2015  Res = Builder.CreateZExtOrTrunc(Res, II->getType());
2016  if (Arg != Vect &&
2017  cast<Instruction>(Arg)->getOpcode() == Instruction::SExt)
2018  Res = Builder.CreateNeg(Res);
2019  return replaceInstUsesWith(CI, Res);
2020  }
2021  }
2022  }
2024  }
2025  case Intrinsic::vector_reduce_xor: {
2026  if (IID == Intrinsic::vector_reduce_xor) {
2027  // Convert vector_reduce_xor(zext(<n x i1>)) to
2028  // (ZExtOrTrunc(ctpop(bitcast <n x i1> to iN) & 1)).
2029  // Convert vector_reduce_xor(sext(<n x i1>)) to
2030  // -(ZExtOrTrunc(ctpop(bitcast <n x i1> to iN) & 1)).
2031  // Convert vector_reduce_xor(<n x i1>) to
2032  // ZExtOrTrunc(ctpop(bitcast <n x i1> to iN) & 1).
2033  Value *Arg = II->getArgOperand(0);
2034  Value *Vect;
2035  if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
2036  if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
2037  if (FTy->getElementType() == Builder.getInt1Ty()) {
2038  Value *V = Builder.CreateBitCast(
2039  Vect, Builder.getIntNTy(FTy->getNumElements()));
2040  Value *Res = Builder.CreateUnaryIntrinsic(Intrinsic::ctpop, V);
2041  Res = Builder.CreateAnd(Res, ConstantInt::get(Res->getType(), 1));
2042  if (Res->getType() != II->getType())
2043  Res = Builder.CreateZExtOrTrunc(Res, II->getType());
2044  if (Arg != Vect &&
2045  cast<Instruction>(Arg)->getOpcode() == Instruction::SExt)
2046  Res = Builder.CreateNeg(Res);
2047  return replaceInstUsesWith(CI, Res);
2048  }
2049  }
2050  }
2052  }
2053  case Intrinsic::vector_reduce_mul: {
2054  if (IID == Intrinsic::vector_reduce_mul) {
2055  // Multiplicative reduction over the vector with (potentially-extended)
2056  // i1 element type is actually a (potentially zero-extended)
2057  // logical `and` reduction over the original non-extended value:
2058  // vector_reduce_mul(?ext(<n x i1>))
2059  // -->
2060  // zext(vector_reduce_and(<n x i1>))
2061  Value *Arg = II->getArgOperand(0);
2062  Value *Vect;
2063  if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
2064  if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
2065  if (FTy->getElementType() == Builder.getInt1Ty()) {
2066  Value *Res = Builder.CreateAndReduce(Vect);
2067  if (Res->getType() != II->getType())
2068  Res = Builder.CreateZExt(Res, II->getType());
2069  return replaceInstUsesWith(CI, Res);
2070  }
2071  }
2072  }
2074  }
2075  case Intrinsic::vector_reduce_umin:
2076  case Intrinsic::vector_reduce_umax: {
2077  if (IID == Intrinsic::vector_reduce_umin ||
2078  IID == Intrinsic::vector_reduce_umax) {
2079  // UMin/UMax reduction over the vector with (potentially-extended)
2080  // i1 element type is actually a (potentially-extended)
2081  // logical `and`/`or` reduction over the original non-extended value:
2082  // vector_reduce_u{min,max}(?ext(<n x i1>))
2083  // -->
2084  // ?ext(vector_reduce_{and,or}(<n x i1>))
2085  Value *Arg = II->getArgOperand(0);
2086  Value *Vect;
2087  if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
2088  if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
2089  if (FTy->getElementType() == Builder.getInt1Ty()) {
2090  Value *Res = IID == Intrinsic::vector_reduce_umin
2091  ? Builder.CreateAndReduce(Vect)
2092  : Builder.CreateOrReduce(Vect);
2093  if (Arg != Vect)
2094  Res = Builder.CreateCast(cast<CastInst>(Arg)->getOpcode(), Res,
2095  II->getType());
2096  return replaceInstUsesWith(CI, Res);
2097  }
2098  }
2099  }
2101  }
2102  case Intrinsic::vector_reduce_smin:
2103  case Intrinsic::vector_reduce_smax: {
2104  if (IID == Intrinsic::vector_reduce_smin ||
2105  IID == Intrinsic::vector_reduce_smax) {
2106  // SMin/SMax reduction over the vector with (potentially-extended)
2107  // i1 element type is actually a (potentially-extended)
2108  // logical `and`/`or` reduction over the original non-extended value:
2109  // vector_reduce_s{min,max}(<n x i1>)
2110  // -->
2111  // vector_reduce_{or,and}(<n x i1>)
2112  // and
2113  // vector_reduce_s{min,max}(sext(<n x i1>))
2114  // -->
2115  // sext(vector_reduce_{or,and}(<n x i1>))
2116  // and
2117  // vector_reduce_s{min,max}(zext(<n x i1>))
2118  // -->
2119  // zext(vector_reduce_{and,or}(<n x i1>))
2120  Value *Arg = II->getArgOperand(0);
2121  Value *Vect;
2122  if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
2123  if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
2124  if (FTy->getElementType() == Builder.getInt1Ty()) {
2125  Instruction::CastOps ExtOpc = Instruction::CastOps::CastOpsEnd;
2126  if (Arg != Vect)
2127  ExtOpc = cast<CastInst>(Arg)->getOpcode();
2128  Value *Res = ((IID == Intrinsic::vector_reduce_smin) ==
2129  (ExtOpc == Instruction::CastOps::ZExt))
2130  ? Builder.CreateAndReduce(Vect)
2131  : Builder.CreateOrReduce(Vect);
2132  if (Arg != Vect)
2133  Res = Builder.CreateCast(ExtOpc, Res, II->getType());
2134  return replaceInstUsesWith(CI, Res);
2135  }
2136  }
2137  }
2139  }
2140  case Intrinsic::vector_reduce_fmax:
2141  case Intrinsic::vector_reduce_fmin:
2142  case Intrinsic::vector_reduce_fadd:
2143  case Intrinsic::vector_reduce_fmul: {
2144  bool CanBeReassociated = (IID != Intrinsic::vector_reduce_fadd &&
2145  IID != Intrinsic::vector_reduce_fmul) ||
2146  II->hasAllowReassoc();
2147  const unsigned ArgIdx = (IID == Intrinsic::vector_reduce_fadd ||
2148  IID == Intrinsic::vector_reduce_fmul)
2149  ? 1
2150  : 0;
2151  Value *Arg = II->getArgOperand(ArgIdx);
2152  Value *V;
2154  if (!isa<FixedVectorType>(Arg->getType()) || !CanBeReassociated ||
2155  !match(Arg, m_Shuffle(m_Value(V), m_Undef(), m_Mask(Mask))) ||
2156  !cast<ShuffleVectorInst>(Arg)->isSingleSource())
2157  break;
2158  int Sz = Mask.size();
2159  SmallBitVector UsedIndices(Sz);
2160  for (int Idx : Mask) {
2161  if (Idx == UndefMaskElem || UsedIndices.test(Idx))
2162  break;
2163  UsedIndices.set(Idx);
2164  }
2165  // Can remove shuffle iff just shuffled elements, no repeats, undefs, or
2166  // other changes.
2167  if (UsedIndices.all()) {
2168  replaceUse(II->getOperandUse(ArgIdx), V);
2169  return nullptr;
2170  }
2171  break;
2172  }
2173  default: {
2174  // Handle target specific intrinsics
2175  Optional<Instruction *> V = targetInstCombineIntrinsic(*II);
2176  if (V.hasValue())
2177  return V.getValue();
2178  break;
2179  }
2180  }
2181  // Some intrinsics (like experimental_gc_statepoint) can be used in invoke
2182  // context, so it is handled in visitCallBase and we should trigger it.
2183  return visitCallBase(*II);
2184 }
2185 
2186 // Fence instruction simplification
2188  // Remove identical consecutive fences.
2190  if (auto *NFI = dyn_cast<FenceInst>(Next))
2191  if (FI.isIdenticalTo(NFI))
2192  return eraseInstFromFunction(FI);
2193  return nullptr;
2194 }
2195 
2196 // InvokeInst simplification
2198  return visitCallBase(II);
2199 }
2200 
2201 // CallBrInst simplification
2203  return visitCallBase(CBI);
2204 }
2205 
2206 /// If this cast does not affect the value passed through the varargs area, we
2207 /// can eliminate the use of the cast.
2208 static bool isSafeToEliminateVarargsCast(const CallBase &Call,
2209  const DataLayout &DL,
2210  const CastInst *const CI,
2211  const int ix) {
2212  if (!CI->isLosslessCast())
2213  return false;
2214 
2215  // If this is a GC intrinsic, avoid munging types. We need types for
2216  // statepoint reconstruction in SelectionDAG.
2217  // TODO: This is probably something which should be expanded to all
2218  // intrinsics since the entire point of intrinsics is that
2219  // they are understandable by the optimizer.
2220  if (isa<GCStatepointInst>(Call) || isa<GCRelocateInst>(Call) ||
2221  isa<GCResultInst>(Call))
2222  return false;
2223 
2224  // Opaque pointers are compatible with any byval types.
2225  PointerType *SrcTy = cast<PointerType>(CI->getOperand(0)->getType());
2226  if (SrcTy->isOpaque())
2227  return true;
2228 
2229  // The size of ByVal or InAlloca arguments is derived from the type, so we
2230  // can't change to a type with a different size. If the size were
2231  // passed explicitly we could avoid this check.
2232  if (!Call.isPassPointeeByValueArgument(ix))
2233  return true;
2234 
2235  // The transform currently only handles type replacement for byval, not other
2236  // type-carrying attributes.
2237  if (!Call.isByValArgument(ix))
2238  return false;
2239 
2240  Type *SrcElemTy = SrcTy->getElementType();
2241  Type *DstElemTy = Call.getParamByValType(ix);
2242  if (!SrcElemTy->isSized() || !DstElemTy->isSized())
2243  return false;
2244  if (DL.getTypeAllocSize(SrcElemTy) != DL.getTypeAllocSize(DstElemTy))
2245  return false;
2246  return true;
2247 }
2248 
2249 Instruction *InstCombinerImpl::tryOptimizeCall(CallInst *CI) {
2250  if (!CI->getCalledFunction()) return nullptr;
2251 
2252  auto InstCombineRAUW = [this](Instruction *From, Value *With) {
2253  replaceInstUsesWith(*From, With);
2254  };
2255  auto InstCombineErase = [this](Instruction *I) {
2256  eraseInstFromFunction(*I);
2257  };
2258  LibCallSimplifier Simplifier(DL, &TLI, ORE, BFI, PSI, InstCombineRAUW,
2259  InstCombineErase);
2260  if (Value *With = Simplifier.optimizeCall(CI, Builder)) {
2261  ++NumSimplified;
2262  return CI->use_empty() ? CI : replaceInstUsesWith(*CI, With);
2263  }
2264 
2265  return nullptr;
2266 }
2267 
2269  // Strip off at most one level of pointer casts, looking for an alloca. This
2270  // is good enough in practice and simpler than handling any number of casts.
2271  Value *Underlying = TrampMem->stripPointerCasts();
2272  if (Underlying != TrampMem &&
2273  (!Underlying->hasOneUse() || Underlying->user_back() != TrampMem))
2274  return nullptr;
2275  if (!isa<AllocaInst>(Underlying))
2276  return nullptr;
2277 
2278  IntrinsicInst *InitTrampoline = nullptr;
2279  for (User *U : TrampMem->users()) {
2280  IntrinsicInst *II = dyn_cast<IntrinsicInst>(U);
2281  if (!II)
2282  return nullptr;
2283  if (II->getIntrinsicID() == Intrinsic::init_trampoline) {
2284  if (InitTrampoline)
2285  // More than one init_trampoline writes to this value. Give up.
2286  return nullptr;
2287  InitTrampoline = II;
2288  continue;
2289  }
2290  if (II->getIntrinsicID() == Intrinsic::adjust_trampoline)
2291  // Allow any number of calls to adjust.trampoline.
2292  continue;
2293  return nullptr;
2294  }
2295 
2296  // No call to init.trampoline found.
2297  if (!InitTrampoline)
2298  return nullptr;
2299 
2300  // Check that the alloca is being used in the expected way.
2301  if (InitTrampoline->getOperand(0) != TrampMem)
2302  return nullptr;
2303 
2304  return InitTrampoline;
2305 }
2306 
2308  Value *TrampMem) {
2309  // Visit all the previous instructions in the basic block, and try to find a
2310  // init.trampoline which has a direct path to the adjust.trampoline.
2311  for (BasicBlock::iterator I = AdjustTramp->getIterator(),
2312  E = AdjustTramp->getParent()->begin();
2313  I != E;) {
2314  Instruction *Inst = &*--I;
2315  if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
2316  if (II->getIntrinsicID() == Intrinsic::init_trampoline &&
2317  II->getOperand(0) == TrampMem)
2318  return II;
2319  if (Inst->mayWriteToMemory())
2320  return nullptr;
2321  }
2322  return nullptr;
2323 }
2324 
2325 // Given a call to llvm.adjust.trampoline, find and return the corresponding
2326 // call to llvm.init.trampoline if the call to the trampoline can be optimized
2327 // to a direct call to a function. Otherwise return NULL.
2329  Callee = Callee->stripPointerCasts();
2330  IntrinsicInst *AdjustTramp = dyn_cast<IntrinsicInst>(Callee);
2331  if (!AdjustTramp ||
2332  AdjustTramp->getIntrinsicID() != Intrinsic::adjust_trampoline)
2333  return nullptr;
2334 
2335  Value *TrampMem = AdjustTramp->getOperand(0);
2336 
2338  return IT;
2339  if (IntrinsicInst *IT = findInitTrampolineFromBB(AdjustTramp, TrampMem))
2340  return IT;
2341  return nullptr;
2342 }
2343 
2344 void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI) {
2345  unsigned NumArgs = Call.getNumArgOperands();
2346  ConstantInt *Op0C = dyn_cast<ConstantInt>(Call.getOperand(0));
2347  ConstantInt *Op1C =
2348  (NumArgs == 1) ? nullptr : dyn_cast<ConstantInt>(Call.getOperand(1));
2349  // Bail out if the allocation size is zero (or an invalid alignment of zero
2350  // with aligned_alloc).
2351  if ((Op0C && Op0C->isNullValue()) || (Op1C && Op1C->isNullValue()))
2352  return;
2353 
2354  if (isMallocLikeFn(&Call, TLI) && Op0C) {
2355  if (isOpNewLikeFn(&Call, TLI))
2356  Call.addAttribute(AttributeList::ReturnIndex,
2358  Call.getContext(), Op0C->getZExtValue()));
2359  else
2360  Call.addAttribute(AttributeList::ReturnIndex,
2362  Call.getContext(), Op0C->getZExtValue()));
2363  } else if (isAlignedAllocLikeFn(&Call, TLI)) {
2364  if (Op1C)
2365  Call.addAttribute(AttributeList::ReturnIndex,
2367  Call.getContext(), Op1C->getZExtValue()));
2368  // Add alignment attribute if alignment is a power of two constant.
2369  if (Op0C && Op0C->getValue().ult(llvm::Value::MaximumAlignment) &&
2370  isKnownNonZero(Call.getOperand(1), DL, 0, &AC, &Call, &DT)) {
2371  uint64_t AlignmentVal = Op0C->getZExtValue();
2372  if (llvm::isPowerOf2_64(AlignmentVal)) {
2373  Call.removeAttribute(AttributeList::ReturnIndex, Attribute::Alignment);
2374  Call.addAttribute(AttributeList::ReturnIndex,
2375  Attribute::getWithAlignment(Call.getContext(),
2376  Align(AlignmentVal)));
2377  }
2378  }
2379  } else if (isReallocLikeFn(&Call, TLI) && Op1C) {
2380  Call.addAttribute(AttributeList::ReturnIndex,
2382  Call.getContext(), Op1C->getZExtValue()));
2383  } else if (isCallocLikeFn(&Call, TLI) && Op0C && Op1C) {
2384  bool Overflow;
2385  const APInt &N = Op0C->getValue();
2386  APInt Size = N.umul_ov(Op1C->getValue(), Overflow);
2387  if (!Overflow)
2388  Call.addAttribute(AttributeList::ReturnIndex,
2390  Call.getContext(), Size.getZExtValue()));
2391  } else if (isStrdupLikeFn(&Call, TLI)) {
2392  uint64_t Len = GetStringLength(Call.getOperand(0));
2393  if (Len) {
2394  // strdup
2395  if (NumArgs == 1)
2396  Call.addAttribute(AttributeList::ReturnIndex,
2398  Call.getContext(), Len));
2399  // strndup
2400  else if (NumArgs == 2 && Op1C)
2401  Call.addAttribute(
2404  Call.getContext(), std::min(Len, Op1C->getZExtValue() + 1)));
2405  }
2406  }
2407 }
2408 
2409 /// Improvements for call, callbr and invoke instructions.
2410 Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
2411  if (isAllocationFn(&Call, &TLI))
2412  annotateAnyAllocSite(Call, &TLI);
2413 
2414  bool Changed = false;
2415 
2416  // Mark any parameters that are known to be non-null with the nonnull
2417  // attribute. This is helpful for inlining calls to functions with null
2418  // checks on their arguments.
2419  SmallVector<unsigned, 4> ArgNos;
2420  unsigned ArgNo = 0;
2421 
2422  for (Value *V : Call.args()) {
2423  if (V->getType()->isPointerTy() &&
2424  !Call.paramHasAttr(ArgNo, Attribute::NonNull) &&
2425  isKnownNonZero(V, DL, 0, &AC, &Call, &DT))
2426  ArgNos.push_back(ArgNo);
2427  ArgNo++;
2428  }
2429 
2430  assert(ArgNo == Call.arg_size() && "sanity check");
2431 
2432  if (!ArgNos.empty()) {
2433  AttributeList AS = Call.getAttributes();
2434  LLVMContext &Ctx = Call.getContext();
2435  AS = AS.addParamAttribute(Ctx, ArgNos,
2436  Attribute::get(Ctx, Attribute::NonNull));
2437  Call.setAttributes(AS);
2438  Changed = true;
2439  }
2440 
2441  // If the callee is a pointer to a function, attempt to move any casts to the
2442  // arguments of the call/callbr/invoke.
2443  Value *Callee = Call.getCalledOperand();
2444  if (!isa<Function>(Callee) && transformConstExprCastCall(Call))
2445  return nullptr;
2446 
2447  if (Function *CalleeF = dyn_cast<Function>(Callee)) {
2448  // Remove the convergent attr on calls when the callee is not convergent.
2449  if (Call.isConvergent() && !CalleeF->isConvergent() &&
2450  !CalleeF->isIntrinsic()) {
2451  LLVM_DEBUG(dbgs() << "Removing convergent attr from instr " << Call
2452  << "\n");
2453  Call.setNotConvergent();
2454  return &Call;
2455  }
2456 
2457  // If the call and callee calling conventions don't match, and neither one
2458  // of the calling conventions is compatible with C calling convention
2459  // this call must be unreachable, as the call is undefined.
2460  if ((CalleeF->getCallingConv() != Call.getCallingConv() &&
2461  !(CalleeF->getCallingConv() == llvm::CallingConv::C &&
2463  !(Call.getCallingConv() == llvm::CallingConv::C &&
2465  // Only do this for calls to a function with a body. A prototype may
2466  // not actually end up matching the implementation's calling conv for a
2467  // variety of reasons (e.g. it may be written in assembly).
2468  !CalleeF->isDeclaration()) {
2469  Instruction *OldCall = &Call;
2470  CreateNonTerminatorUnreachable(OldCall);
2471  // If OldCall does not return void then replaceInstUsesWith poison.
2472  // This allows ValueHandlers and custom metadata to adjust itself.
2473  if (!OldCall->getType()->isVoidTy())
2474  replaceInstUsesWith(*OldCall, PoisonValue::get(OldCall->getType()));
2475  if (isa<CallInst>(OldCall))
2476  return eraseInstFromFunction(*OldCall);
2477 
2478  // We cannot remove an invoke or a callbr, because it would change thexi
2479  // CFG, just change the callee to a null pointer.
2480  cast<CallBase>(OldCall)->setCalledFunction(
2481  CalleeF->getFunctionType(),
2482  Constant::getNullValue(CalleeF->getType()));
2483  return nullptr;
2484  }
2485  }
2486 
2487  // Calling a null function pointer is undefined if a null address isn't
2488  // dereferenceable.
2489  if ((isa<ConstantPointerNull>(Callee) &&
2490  !NullPointerIsDefined(Call.getFunction())) ||
2491  isa<UndefValue>(Callee)) {
2492  // If Call does not return void then replaceInstUsesWith poison.
2493  // This allows ValueHandlers and custom metadata to adjust itself.
2494  if (!Call.getType()->isVoidTy())
2495  replaceInstUsesWith(Call, PoisonValue::get(Call.getType()));
2496 
2497  if (Call.isTerminator()) {
2498  // Can't remove an invoke or callbr because we cannot change the CFG.
2499  return nullptr;
2500  }
2501 
2502  // This instruction is not reachable, just remove it.
2503  CreateNonTerminatorUnreachable(&Call);
2504  return eraseInstFromFunction(Call);
2505  }
2506 
2507  if (IntrinsicInst *II = findInitTrampoline(Callee))
2508  return transformCallThroughTrampoline(Call, *II);
2509 
2510  // TODO: Drop this transform once opaque pointer transition is done.
2511  FunctionType *FTy = Call.getFunctionType();
2512  if (FTy->isVarArg()) {
2513  int ix = FTy->getNumParams();
2514  // See if we can optimize any arguments passed through the varargs area of
2515  // the call.
2516  for (auto I = Call.arg_begin() + FTy->getNumParams(), E = Call.arg_end();
2517  I != E; ++I, ++ix) {
2518  CastInst *CI = dyn_cast<CastInst>(*I);
2519  if (CI && isSafeToEliminateVarargsCast(Call, DL, CI, ix)) {
2520  replaceUse(*I, CI->getOperand(0));
2521 
2522  // Update the byval type to match the pointer type.
2523  // Not necessary for opaque pointers.
2524  PointerType *NewTy = cast<PointerType>(CI->getOperand(0)->getType());
2525  if (!NewTy->isOpaque() && Call.isByValArgument(ix)) {
2526  Call.removeParamAttr(ix, Attribute::ByVal);
2527  Call.addParamAttr(
2529  Call.getContext(), NewTy->getElementType()));
2530  }
2531  Changed = true;
2532  }
2533  }
2534  }
2535 
2536  if (isa<InlineAsm>(Callee) && !Call.doesNotThrow()) {
2537  InlineAsm *IA = cast<InlineAsm>(Callee);
2538  if (!IA->canThrow()) {
2539  // Normal inline asm calls cannot throw - mark them
2540  // 'nounwind'.
2541  Call.setDoesNotThrow();
2542  Changed = true;
2543  }
2544  }
2545 
2546  // Try to optimize the call if possible, we require DataLayout for most of
2547  // this. None of these calls are seen as possibly dead so go ahead and
2548  // delete the instruction now.
2549  if (CallInst *CI = dyn_cast<CallInst>(&Call)) {
2550  Instruction *I = tryOptimizeCall(CI);
2551  // If we changed something return the result, etc. Otherwise let
2552  // the fallthrough check.
2553  if (I) return eraseInstFromFunction(*I);
2554  }
2555 
2556  if (!Call.use_empty() && !Call.isMustTailCall())
2557  if (Value *ReturnedArg = Call.getReturnedArgOperand()) {
2558  Type *CallTy = Call.getType();
2559  Type *RetArgTy = ReturnedArg->getType();
2560  if (RetArgTy->canLosslesslyBitCastTo(CallTy))
2561  return replaceInstUsesWith(
2562  Call, Builder.CreateBitOrPointerCast(ReturnedArg, CallTy));
2563  }
2564 
2565  if (isAllocLikeFn(&Call, &TLI))
2566  return visitAllocSite(Call);
2567 
2568  // Handle intrinsics which can be used in both call and invoke context.
2569  switch (Call.getIntrinsicID()) {
2570  case Intrinsic::experimental_gc_statepoint: {
2571  GCStatepointInst &GCSP = *cast<GCStatepointInst>(&Call);
2572  SmallPtrSet<Value *, 32> LiveGcValues;
2573  for (const GCRelocateInst *Reloc : GCSP.getGCRelocates()) {
2574  GCRelocateInst &GCR = *const_cast<GCRelocateInst *>(Reloc);
2575 
2576  // Remove the relocation if unused.
2577  if (GCR.use_empty()) {
2578  eraseInstFromFunction(GCR);
2579  continue;
2580  }
2581 
2582  Value *DerivedPtr = GCR.getDerivedPtr();
2583  Value *BasePtr = GCR.getBasePtr();
2584 
2585  // Undef is undef, even after relocation.
2586  if (isa<UndefValue>(DerivedPtr) || isa<UndefValue>(BasePtr)) {
2587  replaceInstUsesWith(GCR, UndefValue::get(GCR.getType()));
2588  eraseInstFromFunction(GCR);
2589  continue;
2590  }
2591 
2592  if (auto *PT = dyn_cast<PointerType>(GCR.getType())) {
2593  // The relocation of null will be null for most any collector.
2594  // TODO: provide a hook for this in GCStrategy. There might be some
2595  // weird collector this property does not hold for.
2596  if (isa<ConstantPointerNull>(DerivedPtr)) {
2597  // Use null-pointer of gc_relocate's type to replace it.
2598  replaceInstUsesWith(GCR, ConstantPointerNull::get(PT));
2599  eraseInstFromFunction(GCR);
2600  continue;
2601  }
2602 
2603  // isKnownNonNull -> nonnull attribute
2604  if (!GCR.hasRetAttr(Attribute::NonNull) &&
2605  isKnownNonZero(DerivedPtr, DL, 0, &AC, &Call, &DT)) {
2606  GCR.addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
2607  // We discovered new fact, re-check users.
2608  Worklist.pushUsersToWorkList(GCR);
2609  }
2610  }
2611 
2612  // If we have two copies of the same pointer in the statepoint argument
2613  // list, canonicalize to one. This may let us common gc.relocates.
2614  if (GCR.getBasePtr() == GCR.getDerivedPtr() &&
2615  GCR.getBasePtrIndex() != GCR.getDerivedPtrIndex()) {
2616  auto *OpIntTy = GCR.getOperand(2)->getType();
2617  GCR.setOperand(2, ConstantInt::get(OpIntTy, GCR.getBasePtrIndex()));
2618  }
2619 
2620  // TODO: bitcast(relocate(p)) -> relocate(bitcast(p))
2621  // Canonicalize on the type from the uses to the defs
2622 
2623  // TODO: relocate((gep p, C, C2, ...)) -> gep(relocate(p), C, C2, ...)
2624  LiveGcValues.insert(BasePtr);
2625  LiveGcValues.insert(DerivedPtr);
2626  }
2629  unsigned NumOfGCLives = LiveGcValues.size();
2630  if (!Bundle.hasValue() || NumOfGCLives == Bundle->Inputs.size())
2631  break;
2632  // We can reduce the size of gc live bundle.
2634  std::vector<Value *> NewLiveGc;
2635  for (unsigned I = 0, E = Bundle->Inputs.size(); I < E; ++I) {
2636  Value *V = Bundle->Inputs[I];
2637  if (Val2Idx.count(V))
2638  continue;
2639  if (LiveGcValues.count(V)) {
2640  Val2Idx[V] = NewLiveGc.size();
2641  NewLiveGc.push_back(V);
2642  } else
2643  Val2Idx[V] = NumOfGCLives;
2644  }
2645  // Update all gc.relocates
2646  for (const GCRelocateInst *Reloc : GCSP.getGCRelocates()) {
2647  GCRelocateInst &GCR = *const_cast<GCRelocateInst *>(Reloc);
2648  Value *BasePtr = GCR.getBasePtr();
2649  assert(Val2Idx.count(BasePtr) && Val2Idx[BasePtr] != NumOfGCLives &&
2650  "Missed live gc for base pointer");
2651  auto *OpIntTy1 = GCR.getOperand(1)->getType();
2652  GCR.setOperand(1, ConstantInt::get(OpIntTy1, Val2Idx[BasePtr]));
2653  Value *DerivedPtr = GCR.getDerivedPtr();
2654  assert(Val2Idx.count(DerivedPtr) && Val2Idx[DerivedPtr] != NumOfGCLives &&
2655  "Missed live gc for derived pointer");
2656  auto *OpIntTy2 = GCR.getOperand(2)->getType();
2657  GCR.setOperand(2, ConstantInt::get(OpIntTy2, Val2Idx[DerivedPtr]));
2658  }
2659  // Create new statepoint instruction.
2660  OperandBundleDef NewBundle("gc-live", NewLiveGc);
2661  return CallBase::Create(&Call, NewBundle);
2662  }
2663  default: { break; }
2664  }
2665 
2666  return Changed ? &Call : nullptr;
2667 }
2668 
2669 /// If the callee is a constexpr cast of a function, attempt to move the cast to
2670 /// the arguments of the call/callbr/invoke.
2671 bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
2672  auto *Callee =
2673  dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts());
2674  if (!Callee)
2675  return false;
2676 
2677  // If this is a call to a thunk function, don't remove the cast. Thunks are
2678  // used to transparently forward all incoming parameters and outgoing return
2679  // values, so it's important to leave the cast in place.
2680  if (Callee->hasFnAttribute("thunk"))
2681  return false;
2682 
2683  // If this is a musttail call, the callee's prototype must match the caller's
2684  // prototype with the exception of pointee types. The code below doesn't
2685  // implement that, so we can't do this transform.
2686  // TODO: Do the transform if it only requires adding pointer casts.
2687  if (Call.isMustTailCall())
2688  return false;
2689 
2690  Instruction *Caller = &Call;
2691  const AttributeList &CallerPAL = Call.getAttributes();
2692 
2693  // Okay, this is a cast from a function to a different type. Unless doing so
2694  // would cause a type conversion of one of our arguments, change this call to
2695  // be a direct call with arguments casted to the appropriate types.
2697  Type *OldRetTy = Caller->getType();
2698  Type *NewRetTy = FT->getReturnType();
2699 
2700  // Check to see if we are changing the return type...
2701  if (OldRetTy != NewRetTy) {
2702 
2703  if (NewRetTy->isStructTy())
2704  return false; // TODO: Handle multiple return values.
2705 
2706  if (!CastInst::isBitOrNoopPointerCastable(NewRetTy, OldRetTy, DL)) {
2707  if (Callee->isDeclaration())
2708  return false; // Cannot transform this return value.
2709 
2710  if (!Caller->use_empty() &&
2711  // void -> non-void is handled specially
2712  !NewRetTy->isVoidTy())
2713  return false; // Cannot transform this return value.
2714  }
2715 
2716  if (!CallerPAL.isEmpty() && !Caller->use_empty()) {
2717  AttrBuilder RAttrs(CallerPAL, AttributeList::ReturnIndex);
2718  if (RAttrs.overlaps(AttributeFuncs::typeIncompatible(NewRetTy)))
2719  return false; // Attribute not compatible with transformed value.
2720  }
2721 
2722  // If the callbase is an invoke/callbr instruction, and the return value is
2723  // used by a PHI node in a successor, we cannot change the return type of
2724  // the call because there is no place to put the cast instruction (without
2725  // breaking the critical edge). Bail out in this case.
2726  if (!Caller->use_empty()) {
2727  if (InvokeInst *II = dyn_cast<InvokeInst>(Caller))
2728  for (User *U : II->users())
2729  if (PHINode *PN = dyn_cast<PHINode>(U))
2730  if (PN->getParent() == II->getNormalDest() ||
2731  PN->getParent() == II->getUnwindDest())
2732  return false;
2733  // FIXME: Be conservative for callbr to avoid a quadratic search.
2734  if (isa<CallBrInst>(Caller))
2735  return false;
2736  }
2737  }
2738 
2739  unsigned NumActualArgs = Call.arg_size();
2740  unsigned NumCommonArgs = std::min(FT->getNumParams(), NumActualArgs);
2741 
2742  // Prevent us turning:
2743  // declare void @takes_i32_inalloca(i32* inalloca)
2744  // call void bitcast (void (i32*)* @takes_i32_inalloca to void (i32)*)(i32 0)
2745  //
2746  // into:
2747  // call void @takes_i32_inalloca(i32* null)
2748  //
2749  // Similarly, avoid folding away bitcasts of byval calls.
2750  if (Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca) ||
2751  Callee->getAttributes().hasAttrSomewhere(Attribute::Preallocated) ||
2752  Callee->getAttributes().hasAttrSomewhere(Attribute::ByVal))
2753  return false;
2754 
2755  auto AI = Call.arg_begin();
2756  for (unsigned i = 0, e = NumCommonArgs; i != e; ++i, ++AI) {
2757  Type *ParamTy = FT->getParamType(i);
2758  Type *ActTy = (*AI)->getType();
2759 
2760  if (!CastInst::isBitOrNoopPointerCastable(ActTy, ParamTy, DL))
2761  return false; // Cannot transform this parameter value.
2762 
2763  if (AttrBuilder(CallerPAL.getParamAttributes(i))
2765  return false; // Attribute not compatible with transformed value.
2766 
2767  if (Call.isInAllocaArgument(i))
2768  return false; // Cannot transform to and from inalloca.
2769 
2770  if (CallerPAL.hasParamAttribute(i, Attribute::SwiftError))
2771  return false;
2772 
2773  // If the parameter is passed as a byval argument, then we have to have a
2774  // sized type and the sized type has to have the same size as the old type.
2775  if (ParamTy != ActTy && CallerPAL.hasParamAttribute(i, Attribute::ByVal)) {
2776  PointerType *ParamPTy = dyn_cast<PointerType>(ParamTy);
2777  if (!ParamPTy || !ParamPTy->getElementType()->isSized())
2778  return false;
2779 
2780  Type *CurElTy = Call.getParamByValType(i);
2781  if (DL.getTypeAllocSize(CurElTy) !=
2782  DL.getTypeAllocSize(ParamPTy->getElementType()))
2783  return false;
2784  }
2785  }
2786 
2787  if (Callee->isDeclaration()) {
2788  // Do not delete arguments unless we have a function body.
2789  if (FT->getNumParams() < NumActualArgs && !FT->isVarArg())
2790  return false;
2791 
2792  // If the callee is just a declaration, don't change the varargsness of the
2793  // call. We don't want to introduce a varargs call where one doesn't
2794  // already exist.
2795  PointerType *APTy = cast<PointerType>(Call.getCalledOperand()->getType());
2796  if (FT->isVarArg()!=cast<FunctionType>(APTy->getElementType())->isVarArg())
2797  return false;
2798 
2799  // If both the callee and the cast type are varargs, we still have to make
2800  // sure the number of fixed parameters are the same or we have the same
2801  // ABI issues as if we introduce a varargs call.
2802  if (FT->isVarArg() &&
2803  cast<FunctionType>(APTy->getElementType())->isVarArg() &&
2804  FT->getNumParams() !=
2805  cast<FunctionType>(APTy->getElementType())->getNumParams())
2806  return false;
2807  }
2808 
2809  if (FT->getNumParams() < NumActualArgs && FT->isVarArg() &&
2810  !CallerPAL.isEmpty()) {
2811  // In this case we have more arguments than the new function type, but we
2812  // won't be dropping them. Check that these extra arguments have attributes
2813  // that are compatible with being a vararg call argument.
2814  unsigned SRetIdx;
2815  if (CallerPAL.hasAttrSomewhere(Attribute::StructRet, &SRetIdx) &&
2816  SRetIdx > FT->getNumParams())
2817  return false;
2818  }
2819 
2820  // Okay, we decided that this is a safe thing to do: go ahead and start
2821  // inserting cast instructions as necessary.
2824  Args.reserve(NumActualArgs);
2825  ArgAttrs.reserve(NumActualArgs);
2826 
2827  // Get any return attributes.
2828  AttrBuilder RAttrs(CallerPAL, AttributeList::ReturnIndex);
2829 
2830  // If the return value is not being used, the type may not be compatible
2831  // with the existing attributes. Wipe out any problematic attributes.
2832  RAttrs.remove(AttributeFuncs::typeIncompatible(NewRetTy));
2833 
2834  LLVMContext &Ctx = Call.getContext();
2835  AI = Call.arg_begin();
2836  for (unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
2837  Type *ParamTy = FT->getParamType(i);
2838 
2839  Value *NewArg = *AI;
2840  if ((*AI)->getType() != ParamTy)
2841  NewArg = Builder.CreateBitOrPointerCast(*AI, ParamTy);
2842  Args.push_back(NewArg);
2843 
2844  // Add any parameter attributes.
2845  if (CallerPAL.hasParamAttribute(i, Attribute::ByVal)) {
2846  AttrBuilder AB(CallerPAL.getParamAttributes(i));
2847  AB.addByValAttr(NewArg->getType()->getPointerElementType());
2848  ArgAttrs.push_back(AttributeSet::get(Ctx, AB));
2849  } else
2850  ArgAttrs.push_back(CallerPAL.getParamAttributes(i));
2851  }
2852 
2853  // If the function takes more arguments than the call was taking, add them
2854  // now.
2855  for (unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i) {
2856  Args.push_back(Constant::getNullValue(FT->getParamType(i)));
2857  ArgAttrs.push_back(AttributeSet());
2858  }
2859 
2860  // If we are removing arguments to the function, emit an obnoxious warning.
2861  if (FT->getNumParams() < NumActualArgs) {
2862  // TODO: if (!FT->isVarArg()) this call may be unreachable. PR14722
2863  if (FT->isVarArg()) {
2864  // Add all of the arguments in their promoted form to the arg list.
2865  for (unsigned i = FT->getNumParams(); i != NumActualArgs; ++i, ++AI) {
2866  Type *PTy = getPromotedType((*AI)->getType());
2867  Value *NewArg = *AI;
2868  if (PTy != (*AI)->getType()) {
2869  // Must promote to pass through va_arg area!
2870  Instruction::CastOps opcode =
2871  CastInst::getCastOpcode(*AI, false, PTy, false);
2872  NewArg = Builder.CreateCast(opcode, *AI, PTy);
2873  }
2874  Args.push_back(NewArg);
2875 
2876  // Add any parameter attributes.
2877  ArgAttrs.push_back(CallerPAL.getParamAttributes(i));
2878  }
2879  }
2880  }
2881 
2882  AttributeSet FnAttrs = CallerPAL.getFnAttributes();
2883 
2884  if (NewRetTy->isVoidTy())
2885  Caller->setName(""); // Void type should not have a name.
2886 
2887  assert((ArgAttrs.size() == FT->getNumParams() || FT->isVarArg()) &&
2888  "missing argument attributes");
2889  AttributeList NewCallerPAL = AttributeList::get(
2890  Ctx, FnAttrs, AttributeSet::get(Ctx, RAttrs), ArgAttrs);
2891 
2893  Call.getOperandBundlesAsDefs(OpBundles);
2894 
2895  CallBase *NewCall;
2896  if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
2897  NewCall = Builder.CreateInvoke(Callee, II->getNormalDest(),
2898  II->getUnwindDest(), Args, OpBundles);
2899  } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(Caller)) {
2900  NewCall = Builder.CreateCallBr(Callee, CBI->getDefaultDest(),
2901  CBI->getIndirectDests(), Args, OpBundles);
2902  } else {
2903  NewCall = Builder.CreateCall(Callee, Args, OpBundles);
2904  cast<CallInst>(NewCall)->setTailCallKind(
2905  cast<CallInst>(Caller)->getTailCallKind());
2906  }
2907  NewCall->takeName(Caller);
2908  NewCall->setCallingConv(Call.getCallingConv());
2909  NewCall->setAttributes(NewCallerPAL);
2910 
2911  // Preserve prof metadata if any.
2912  NewCall->copyMetadata(*Caller, {LLVMContext::MD_prof});
2913 
2914  // Insert a cast of the return type as necessary.
2915  Instruction *NC = NewCall;
2916  Value *NV = NC;
2917  if (OldRetTy != NV->getType() && !Caller->use_empty()) {
2918  if (!NV->getType()->isVoidTy()) {
2919  NV = NC = CastInst::CreateBitOrPointerCast(NC, OldRetTy);
2920  NC->setDebugLoc(Caller->getDebugLoc());
2921 
2922  // If this is an invoke/callbr instruction, we should insert it after the
2923  // first non-phi instruction in the normal successor block.
2924  if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
2925  BasicBlock::iterator I = II->getNormalDest()->getFirstInsertionPt();
2926  InsertNewInstBefore(NC, *I);
2927  } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(Caller)) {
2928  BasicBlock::iterator I = CBI->getDefaultDest()->getFirstInsertionPt();
2929  InsertNewInstBefore(NC, *I);
2930  } else {
2931  // Otherwise, it's a call, just insert cast right after the call.
2932  InsertNewInstBefore(NC, *Caller);
2933  }
2934  Worklist.pushUsersToWorkList(*Caller);
2935  } else {
2936  NV = UndefValue::get(Caller->getType());
2937  }
2938  }
2939 
2940  if (!Caller->use_empty())
2941  replaceInstUsesWith(*Caller, NV);
2942  else if (Caller->hasValueHandle()) {
2943  if (OldRetTy == NV->getType())
2945  else
2946  // We cannot call ValueIsRAUWd with a different type, and the
2947  // actual tracked value will disappear.
2949  }
2950 
2951  eraseInstFromFunction(*Caller);
2952  return true;
2953 }
2954 
2955 /// Turn a call to a function created by init_trampoline / adjust_trampoline
2956 /// intrinsic pair into a direct call to the underlying function.
2957 Instruction *
2958 InstCombinerImpl::transformCallThroughTrampoline(CallBase &Call,
2959  IntrinsicInst &Tramp) {
2960  Value *Callee = Call.getCalledOperand();
2961  Type *CalleeTy = Callee->getType();
2962  FunctionType *FTy = Call.getFunctionType();
2963  AttributeList Attrs = Call.getAttributes();
2964 
2965  // If the call already has the 'nest' attribute somewhere then give up -
2966  // otherwise 'nest' would occur twice after splicing in the chain.
2967  if (Attrs.hasAttrSomewhere(Attribute::Nest))
2968  return nullptr;
2969 
2970  Function *NestF = cast<Function>(Tramp.getArgOperand(1)->stripPointerCasts());
2971  FunctionType *NestFTy = NestF->getFunctionType();
2972 
2973  AttributeList NestAttrs = NestF->getAttributes();
2974  if (!NestAttrs.isEmpty()) {
2975  unsigned NestArgNo = 0;
2976  Type *NestTy = nullptr;
2977  AttributeSet NestAttr;
2978 
2979  // Look for a parameter marked with the 'nest' attribute.
2980  for (FunctionType::param_iterator I = NestFTy->param_begin(),
2981  E = NestFTy->param_end();
2982  I != E; ++NestArgNo, ++I) {
2983  AttributeSet AS = NestAttrs.getParamAttributes(NestArgNo);
2984  if (AS.hasAttribute(Attribute::Nest)) {
2985  // Record the parameter type and any other attributes.
2986  NestTy = *I;
2987  NestAttr = AS;
2988  break;
2989  }
2990  }
2991 
2992  if (NestTy) {
2993  std::vector<Value*> NewArgs;
2994  std::vector<AttributeSet> NewArgAttrs;
2995  NewArgs.reserve(Call.arg_size() + 1);
2996  NewArgAttrs.reserve(Call.arg_size());
2997 
2998  // Insert the nest argument into the call argument list, which may
2999  // mean appending it. Likewise for attributes.
3000 
3001  {
3002  unsigned ArgNo = 0;
3003  auto I = Call.arg_begin(), E = Call.arg_end();
3004  do {
3005  if (ArgNo == NestArgNo) {
3006  // Add the chain argument and attributes.
3007  Value *NestVal = Tramp.getArgOperand(2);
3008  if (NestVal->getType() != NestTy)
3009  NestVal = Builder.CreateBitCast(NestVal, NestTy, "nest");
3010  NewArgs.push_back(NestVal);
3011  NewArgAttrs.push_back(NestAttr);
3012  }
3013 
3014  if (I == E)
3015  break;
3016 
3017  // Add the original argument and attributes.
3018  NewArgs.push_back(*I);
3019  NewArgAttrs.push_back(Attrs.getParamAttributes(ArgNo));
3020 
3021  ++ArgNo;
3022  ++I;
3023  } while (true);
3024  }
3025 
3026  // The trampoline may have been bitcast to a bogus type (FTy).
3027  // Handle this by synthesizing a new function type, equal to FTy
3028  // with the chain parameter inserted.
3029 
3030  std::vector<Type*> NewTypes;
3031  NewTypes.reserve(FTy->getNumParams()+1);
3032 
3033  // Insert the chain's type into the list of parameter types, which may
3034  // mean appending it.
3035  {
3036  unsigned ArgNo = 0;
3038  E = FTy->param_end();
3039 
3040  do {
3041  if (ArgNo == NestArgNo)
3042  // Add the chain's type.
3043  NewTypes.push_back(NestTy);
3044 
3045  if (I == E)
3046  break;
3047 
3048  // Add the original type.
3049  NewTypes.push_back(*I);
3050 
3051  ++ArgNo;
3052  ++I;
3053  } while (true);
3054  }
3055 
3056  // Replace the trampoline call with a direct call. Let the generic
3057  // code sort out any function type mismatches.
3058  FunctionType *NewFTy = FunctionType::get(FTy->getReturnType(), NewTypes,
3059  FTy->isVarArg());
3060  Constant *NewCallee =
3061  NestF->getType() == PointerType::getUnqual(NewFTy) ?
3062  NestF : ConstantExpr::getBitCast(NestF,
3063  PointerType::getUnqual(NewFTy));
3064  AttributeList NewPAL =
3065  AttributeList::get(FTy->getContext(), Attrs.getFnAttributes(),
3066  Attrs.getRetAttributes(), NewArgAttrs);
3067 
3069  Call.getOperandBundlesAsDefs(OpBundles);
3070 
3071  Instruction *NewCaller;
3072  if (InvokeInst *II = dyn_cast<InvokeInst>(&Call)) {
3073  NewCaller = InvokeInst::Create(NewFTy, NewCallee,
3074  II->getNormalDest(), II->getUnwindDest(),
3075  NewArgs, OpBundles);
3076  cast<InvokeInst>(NewCaller)->setCallingConv(II->getCallingConv());
3077  cast<InvokeInst>(NewCaller)->setAttributes(NewPAL);
3078  } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(&Call)) {
3079  NewCaller =
3080  CallBrInst::Create(NewFTy, NewCallee, CBI->getDefaultDest(),
3081  CBI->getIndirectDests(), NewArgs, OpBundles);
3082  cast<CallBrInst>(NewCaller)->setCallingConv(CBI->getCallingConv());
3083  cast<CallBrInst>(NewCaller)->setAttributes(NewPAL);
3084  } else {
3085  NewCaller = CallInst::Create(NewFTy, NewCallee, NewArgs, OpBundles);
3086  cast<CallInst>(NewCaller)->setTailCallKind(
3087  cast<CallInst>(Call).getTailCallKind());
3088  cast<CallInst>(NewCaller)->setCallingConv(
3089  cast<CallInst>(Call).getCallingConv());
3090  cast<CallInst>(NewCaller)->setAttributes(NewPAL);
3091  }
3092  NewCaller->setDebugLoc(Call.getDebugLoc());
3093 
3094  return NewCaller;
3095  }
3096  }
3097 
3098  // Replace the trampoline call with a direct call. Since there is no 'nest'
3099  // parameter, there is no need to adjust the argument list. Let the generic
3100  // code sort out any function type mismatches.
3101  Constant *NewCallee = ConstantExpr::getBitCast(NestF, CalleeTy);
3102  Call.setCalledFunction(FTy, NewCallee);
3103  return &Call;
3104 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::RetainedKnowledge::WasOn
Value * WasOn
Definition: AssumeBundleQueries.h:104
i
i
Definition: README.txt:29
llvm::CallBase::getNumOperandBundles
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Definition: InstrTypes.h:1896
FloatingPointMode.h
llvm::SmallBitVector::set
SmallBitVector & set()
Definition: SmallBitVector.h:363
AssumptionCache.h
llvm::BinaryOpIntrinsic::getBinaryOp
Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
Definition: IntrinsicInst.cpp:507
llvm::PatternMatch::m_FShr
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Definition: PatternMatch.h:2203
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::Type::isSized
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:274
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
MathExtras.h
llvm::APInt::sadd_ov
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
Definition: APInt.cpp:1959
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::isCallocLikeFn
bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as...
Definition: MemoryBuiltins.cpp:291
llvm::maskIsAllOneOrUndef
bool maskIsAllOneOrUndef(Value *Mask)
Given a mask vector of i1, Return true if all of the elements of this predicate mask are known to be ...
Definition: VectorUtils.cpp:906
llvm::CallBase::getOperandBundlesAsDefs
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Definition: Instructions.cpp:365
llvm::InvokeInst::Create
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:3787
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Instruction::getModule
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:66
llvm::Value::dropDroppableUse
static void dropDroppableUse(Use &U)
Remove the droppable use U.
Definition: Value.cpp:205
llvm::CmpInst::ICMP_EQ
@ ICMP_EQ
equal
Definition: InstrTypes.h:741
llvm::OverflowResult::NeverOverflows
@ NeverOverflows
Never overflows.
llvm::ConstantExpr::getNot
static Constant * getNot(Constant *C)
Definition: Constants.cpp:2672
llvm::CallBase::getOperandBundle
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Definition: InstrTypes.h:1976
Optional.h
llvm::PatternMatch::m_Mask
Definition: PatternMatch.h:1524
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::ISD::OR
@ OR
Definition: ISDOpcodes.h:633
llvm::Value::hasOneUse
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition: Value.h:435
llvm::AttrBuilder::overlaps
bool overlaps(const AttrBuilder &B) const
Return true if the builder has any attribute that's in the specified builder.
Definition: Attributes.cpp:1826
InstCombiner.h
llvm::Intrinsic::getDeclaration
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1336
Metadata.h
llvm::AttributeList::hasAttrSomewhere
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
Definition: Attributes.cpp:1413
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:720
llvm::BasicBlock::iterator
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:90
llvm::isSafeToSpeculativelyExecute
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
Definition: ValueTracking.cpp:4583
llvm::ConstantInt::getType
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Definition: Constants.h:173
llvm::InstCombiner::getDominatorTree
DominatorTree & getDominatorTree() const
Definition: InstCombiner.h:369
IntrinsicInst.h
llvm::Type::isPointerTy
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:228
ceil
We have fiadd patterns now but the followings have the same cost and complexity We need a way to specify the later is more profitable def def The FP stackifier should handle simple permutates to reduce number of shuffle e g ceil
Definition: README-FPStack.txt:54
AtomicOrdering.h
llvm::ConstantExpr::getZExt
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2111
llvm::Instruction::getNextNonDebugInstruction
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
Definition: Instruction.cpp:728
Loads.h
GuardWideningWindow
static cl::opt< unsigned > GuardWideningWindow("instcombine-guard-widening-window", cl::init(3), cl::desc("How wide an instruction window to bypass looking for " "another guard"))
llvm::PointerType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:672
llvm::Function
Definition: Function.h:61
llvm::ConstantStruct::get
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1326
llvm::BinaryOperator::CreateNot
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Definition: Instructions.cpp:2694
llvm::IntrinsicInst::getIntrinsicID
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:52
llvm::SelectPatternResult::Flavor
SelectPatternFlavor Flavor
Definition: ValueTracking.h:681
llvm::CallBase::setCalledFunction
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
Definition: InstrTypes.h:1429
llvm::possiblyDemandedEltsInMask
APInt possiblyDemandedEltsInMask(Value *Mask)
Given a mask vector of the form <Y x i1>, return an APInt (of bitwidth Y) for each lane which may be ...
Definition: VectorUtils.cpp:934
llvm::PointerType::get
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Definition: Type.cpp:693
minimum
Should compile r2 movcc movcs str strb mov lr r1 movcs movcc mov lr r1 str mov mov cmp r1 movlo r2 str bx lr r0 mov mov cmp r0 movhs r2 mov r1 bx lr Some of the NEON intrinsics may be appropriate for more general either as target independent intrinsics or perhaps elsewhere in the ARM backend Some of them may also be lowered to target independent and perhaps some new SDNodes could be added For minimum
Definition: README.txt:489
llvm::KnownBits::Zero
APInt Zero
Definition: KnownBits.h:24
C1
instcombine should handle this C2 when C1
Definition: README.txt:263
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:92
llvm::ConstantInt::getValue
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:133
llvm::BinaryOpIntrinsic::getRHS
Value * getRHS() const
Definition: IntrinsicInst.h:554
llvm::ConstantExpr::getSExt
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2097
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::InstCombiner::Builder
BuilderTy & Builder
Definition: InstCombiner.h:56
Statistic.h
InlineAsm.h
llvm::AttributeList::addParamAttribute
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:480
llvm::ConstantExpr::getICmp
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
Definition: Constants.cpp:2490
llvm::BinaryOperator::CreateFDivFMF
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:273
llvm::PatternMatch::m_Add
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1008
llvm::BinaryOpIntrinsic::getLHS
Value * getLHS() const
Definition: IntrinsicInst.h:553
ErrorHandling.h
llvm::CmpInst::makeCmpResultType
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:1031
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:733
llvm::IRBuilder< TargetFolder, IRBuilderCallbackInserter >
llvm::InsertValueInst::Create
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:2524
llvm::X86::SecondMacroFusionInstKind::AB
@ AB
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::CastInst::Create
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Definition: Instructions.cpp:3040
llvm::CmpInst::ICMP_NE
@ ICMP_NE
not equal
Definition: InstrTypes.h:742
llvm::ConstantExpr::getBitCast
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2221
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:327
llvm::SignBitMustBeZero
bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value's sign bit is 0.
Definition: ValueTracking.cpp:3649
ValueTracking.h
llvm::isAssumeWithEmptyBundle
bool isAssumeWithEmptyBundle(AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
Definition: AssumeBundleQueries.cpp:125
Local.h
llvm::AttributeList::get
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:1040
llvm::isAllocLikeFn
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc,...
Definition: MemoryBuiltins.cpp:306
llvm::PatternMatch::m_APFloat
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
Definition: PatternMatch.h:287
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
llvm::minimum
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 minimum semantics.
Definition: APFloat.h:1320
llvm::IRBuilderBase::CreateUnaryIntrinsic
CallInst * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
Definition: IRBuilder.cpp:823
llvm::PatternMatch::m_BitReverse
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
Definition: PatternMatch.h:2164
llvm::AttributeFuncs::typeIncompatible
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
Definition: Attributes.cpp:1885
llvm::isKnownNonZero
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
Definition: ValueTracking.cpp:310
llvm::ConstantInt::getLimitedValue
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
Definition: Constants.h:244
APInt.h
llvm::IRBuilderBase::CreateStripInvariantGroup
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1029
llvm::PatternMatch::m_NegZeroFP
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
Definition: PatternMatch.h:714
llvm::InstCombinerImpl::visitInvokeInst
Instruction * visitInvokeInst(InvokeInst &II)
Definition: InstCombineCalls.cpp:2197
llvm::CmpInst::ICMP_SGT
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:747
llvm::BitmaskEnumDetail::Underlying
std::underlying_type_t< E > Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
Definition: BitmaskEnum.h:90
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::OverflowResult::AlwaysOverflowsLow
@ AlwaysOverflowsLow
Always overflows in the direction of signed/unsigned min value.
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1581
llvm::InstCombinerImpl::visitCallInst
Instruction * visitCallInst(CallInst &CI)
CallInst simplification.
Definition: InstCombineCalls.cpp:801
llvm::InstCombinerImpl::FoldOpIntoSelect
Instruction * FoldOpIntoSelect(Instruction &Op, SelectInst *SI)
Given an instruction with a select as one operand and a constant as the other operand,...
Definition: InstructionCombining.cpp:1002
MemoryBuiltins.h
llvm::AttributeList
Definition: Attributes.h:398
llvm::OperandBundleDefT
A container for an operand bundle being viewed as a set of values rather than a set of uses.
Definition: InstrTypes.h:1114
llvm::CallBase::getFunctionType
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1241
llvm::simplifyRetainedKnowledge
RetainedKnowledge simplifyRetainedKnowledge(AssumeInst *Assume, RetainedKnowledge RK, AssumptionCache *AC, DominatorTree *DT)
canonicalize the RetainedKnowledge RK.
Definition: AssumeBundleBuilder.cpp:316
llvm::FastMathFlags::noSignedZeros
bool noSignedZeros() const
Definition: Operator.h:209
llvm::GCRelocateInst::getBasePtrIndex
unsigned getBasePtrIndex() const
The index into the associate statepoint's argument list which contains the base pointer of the pointe...
Definition: IntrinsicInst.h:1269
llvm::PatternMatch::m_ZExtOrSExtOrSelf
match_combine_or< match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
Definition: PatternMatch.h:1667
llvm::EnableKnowledgeRetention
cl::opt< bool > EnableKnowledgeRetention
enable preservation of attributes in assume like: call void @llvm.assume(i1 true) [ "nonnull"(i32* PT...
Definition: InstCombineCalls.cpp:98
llvm::InstCombinerImpl::replaceInstUsesWith
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
Definition: InstCombineInternal.h:398
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:355
llvm::IRBuilderBase::CreateBinaryIntrinsic
CallInst * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type.
Definition: IRBuilder.cpp:831
llvm::Optional< bool >
foldCttzCtlz
static Instruction * foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC)
Definition: InstCombineCalls.cpp:432
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
llvm::CastInst::getCastOpcode
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
Definition: Instructions.cpp:3322
llvm::FenceInst
An instruction for ordering other memory operations.
Definition: Instructions.h:444
llvm::ConstantAsMetadata::get
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:419
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:136
llvm::Instruction::copyMetadata
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Definition: Instruction.cpp:829
llvm::FunctionType::getNumParams
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:138
llvm::CallBase::getNumArgOperands
unsigned getNumArgOperands() const
Definition: InstrTypes.h:1336
llvm::CastInst::CreateIntegerCast
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
Definition: Instructions.cpp:3206
STLExtras.h
llvm::SmallBitVector::test
bool test(unsigned Idx) const
Definition: SmallBitVector.h:463
llvm::isPowerOf2_32
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:491
llvm::matchSelectPattern
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
Definition: ValueTracking.cpp:6164
llvm::PatternMatch::m_c_And
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
Definition: PatternMatch.h:2242
llvm::BinaryOperator::CreateNeg
NUW NUW NUW NUW Exact static Exact BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
Definition: Instructions.cpp:2654
llvm::CallBase::setDoesNotThrow
void setDoesNotThrow()
Definition: InstrTypes.h:1846
findInitTrampolineFromBB
static IntrinsicInst * findInitTrampolineFromBB(IntrinsicInst *AdjustTramp, Value *TrampMem)
Definition: InstCombineCalls.cpp:2307
llvm::PatternMatch::m_Not
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
Definition: PatternMatch.h:2280
llvm::SelectPatternFlavor
SelectPatternFlavor
Specific patterns of select instructions we can match.
Definition: ValueTracking.h:657
llvm::CallBrInst::Create
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:3995
llvm::BitmaskEnumDetail::Mask
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::InstCombinerImpl::SimplifyAnyMemTransfer
Instruction * SimplifyAnyMemTransfer(AnyMemTransferInst *MI)
Definition: InstCombineCalls.cpp:111
llvm::BasicBlock::rend
reverse_iterator rend()
Definition: BasicBlock.h:303
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:203
llvm::PatternMatch::m_Deferred
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
Definition: PatternMatch.h:820
llvm::isAllocationFn
bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
Definition: MemoryBuiltins.cpp:242
llvm::APIntOps::umin
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
Definition: APInt.h:2178
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:122
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1198
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::FunctionType::isVarArg
bool isVarArg() const
Definition: DerivedTypes.h:122
llvm::Instruction::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1336
KnownBits.h
llvm::KnownBits::countMinTrailingZeros
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition: KnownBits.h:224
floor
We have fiadd patterns now but the followings have the same cost and complexity We need a way to specify the later is more profitable def def The FP stackifier should handle simple permutates to reduce number of shuffle e g floor
Definition: README-FPStack.txt:54
llvm::GCRelocateInst::getDerivedPtrIndex
unsigned getDerivedPtrIndex() const
The index into the associate statepoint's argument list which contains the pointer whose relocation t...
Definition: IntrinsicInst.h:1275
llvm::UndefMaskElem
constexpr int UndefMaskElem
Definition: Instructions.h:1999
AliasAnalysis.h
llvm::PatternMatch::m_OneUse
OneUse_match< T > m_OneUse(const T &SubPattern)
Definition: PatternMatch.h:67
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:288
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::ConstantExpr::getSub
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2689
llvm::InstCombinerImpl::eraseInstFromFunction
Instruction * eraseInstFromFunction(Instruction &I) override
Combiner aware instruction erasure.
Definition: InstCombineInternal.h:446
llvm::GCStatepointInst
Represents a gc.statepoint intrinsic call.
Definition: Statepoint.h:63
llvm::SmallBitVector
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
Definition: SmallBitVector.h:34
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::User::getOperandUse
const Use & getOperandUse(unsigned i) const
Definition: User.h:182
Instruction.h
llvm::PatternMatch::m_APInt
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
Definition: PatternMatch.h:270
llvm::SPF_NABS
@ SPF_NABS
Absolute value.
Definition: ValueTracking.h:666
CommandLine.h
llvm::PatternMatch::m_UMax
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1875
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::KnownBits::isNonNegative
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition: KnownBits.h:99
llvm::Instruction::getOpcode
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:160
llvm::MinAlign
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Definition: MathExtras.h:672
llvm::APInt::isNonNegative
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition: APInt.h:369
llvm::isValidAssumeForContext
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
Definition: ValueTracking.cpp:521
llvm::SelectInst::Create
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Definition: Instructions.h:1771
llvm::SPII::Load
@ Load
Definition: SparcInstrInfo.h:32
InstCombineInternal.h
llvm::PatternMatch::m_Select
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
Definition: PatternMatch.h:1472
llvm::SimplifyCall
Value * SimplifyCall(CallBase *Call, const SimplifyQuery &Q)
Given a callsite, fold the result or return null.
Definition: InstructionSimplify.cpp:5976
llvm::Constant::containsConstantExpression
bool containsConstantExpression() const
Return true if this is a fixed width vector constant that includes any constant expressions.
Definition: Constants.cpp:336
Constants.h
llvm::maximum
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 maximum semantics.
Definition: APFloat.h:1333
llvm::PatternMatch::match
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
llvm::Constant::isNullValue
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Definition: Constants.cpp:74
llvm::PatternMatch::m_FShl
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Definition: PatternMatch.h:2197
llvm::OverflowResult::MayOverflow
@ MayOverflow
May or may not overflow.
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::User
Definition: User.h:44
Intr
unsigned Intr
Definition: AMDGPUBaseInfo.cpp:1987
llvm::getKnownAlignment
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
Definition: Local.h:223
Intrinsics.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::FunctionType::param_end
param_iterator param_end() const
Definition: DerivedTypes.h:128
llvm::AttributeSet::hasAttribute
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition: Attributes.cpp:659
Twine.h
llvm::AttributeList::getFnAttributes
AttributeSet getFnAttributes() const
The function attributes are returned.
Definition: Attributes.cpp:1383
round
static uint64_t round(uint64_t Acc, uint64_t Input)
Definition: xxhash.cpp:57
InstrTypes.h
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1393
llvm::CallBase::setAttributes
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1472
llvm::BinaryOperator::CreateNSW
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:284
llvm::BasicBlock::begin
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:296
llvm::KnownBits::One
APInt One
Definition: KnownBits.h:25
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
llvm::PatternMatch::m_PosZeroFP
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
Definition: PatternMatch.h:705
llvm::LoadInst::setVolatile
void setVolatile(bool V)
Specify whether this is a volatile load or not.
Definition: Instructions.h:215
llvm::CallInst::Create
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1518
AssumeBundleQueries.h
getOpcode
static Optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:199
llvm::LLVMContext::OB_gc_live
@ OB_gc_live
Definition: LLVMContext.h:95
llvm::CallingConv::C
@ C
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::AttributeList::getParamAttributes
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
Definition: Attributes.cpp:1375
llvm::PatternMatch::m_Instruction
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
Definition: PatternMatch.h:748
AssumeBundleBuilder.h
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
llvm::PatternMatch::m_ZExt
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
Definition: PatternMatch.h:1639
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::SmallBitVector::all
bool all() const
Returns true if all bits are set.
Definition: SmallBitVector.h:213
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::Instruction::CastOps
CastOps
Definition: Instruction.h:801
llvm::PatternMatch::m_FNeg
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
Definition: PatternMatch.h:1063
llvm::SaturatingInst
Represents a saturating add/sub intrinsic.
Definition: IntrinsicInst.h:588
llvm::Constant::getAllOnesValue
static Constant * getAllOnesValue(Type *Ty)
Definition: Constants.cpp:404
llvm::pdb::PDB_SymType::Caller
@ Caller
llvm::PatternMatch::m_ConstantInt
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Definition: PatternMatch.h:145
llvm::FunctionType::param_begin
param_iterator param_begin() const
Definition: DerivedTypes.h:127
llvm::Instruction
Definition: Instruction.h:45
llvm::Type::getScalarSizeInBits
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition: Type.cpp:153
llvm::isDereferenceablePointer
bool isDereferenceablePointer(const Value *V, Type *Ty, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if this is always a dereferenceable pointer.
Definition: Loads.cpp:234
llvm::RetainedKnowledge::ArgValue
unsigned ArgValue
Definition: AssumeBundleQueries.h:103
llvm::PatternMatch::m_UMin
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1881
llvm::PatternMatch::m_c_Or
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
Definition: PatternMatch.h:2249
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
llvm::codeview::EncodedFramePtrReg::BasePtr
@ BasePtr
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1784
llvm::CallBase::bundle_op_info_begin
bundle_op_iterator bundle_op_info_begin()
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:2183
llvm::ConstantExpr::getURem
static Constant * getURem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2725
llvm::InstCombinerImpl
Definition: InstCombineInternal.h:61
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:899
InstCombineWorklist.h
llvm::isReallocLikeFn
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that reallocates memory (e....
Definition: MemoryBuiltins.cpp:313
llvm::FunctionCallee::getFunctionType
FunctionType * getFunctionType()
Definition: DerivedTypes.h:181
llvm::APSInt::getMinValue
static APSInt getMinValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the minimum integer value with the given bit width and signedness.
Definition: APSInt.h:289
llvm::getKnowledgeFromBundle
RetainedKnowledge getKnowledgeFromBundle(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI)
This extracts the Knowledge from an element of an operand bundle.
Definition: AssumeBundleQueries.cpp:99
llvm::AttributeList::hasParamAttribute
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
Definition: Attributes.cpp:1408
llvm::KnownBits::isNegative
bool isNegative() const
Returns true if this value is known to be negative.
Definition: KnownBits.h:96
canonicalizeConstantArg0ToArg1
static CallInst * canonicalizeConstantArg0ToArg1(CallInst &Call)
Definition: InstCombineCalls.cpp:712
PatternMatch.h
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:153
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::Instruction::mayWriteToMemory
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
Definition: Instruction.cpp:584
llvm::PointerType::isOpaque
bool isOpaque() const
Definition: DerivedTypes.h:677
llvm::CallBase::getCallingConv
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1449
llvm::None
const NoneType None
Definition: None.h:23
Statepoint.h
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:345
Type.h
llvm::IRBuilderBase::CreateAddrSpaceCast
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2118
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::AnyMemTransferInst
Definition: IntrinsicInst.h:1007
llvm::Log2_32_Ceil
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:609
llvm::CastInst::isLosslessCast
bool isLosslessCast() const
A lossless cast is one that does not alter the basic value.
Definition: Instructions.cpp:2750
llvm::PatternMatch::m_One
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
Definition: PatternMatch.h:513
llvm::Instruction::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:282
llvm::SimplifyFMulInst
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FMul, fold the result or return null.
Definition: InstructionSimplify.cpp:5070
llvm::OverflowResult
OverflowResult
Definition: ValueTracking.h:487
llvm::maxnum
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
Definition: APFloat.h:1309
findInitTrampolineFromAlloca
static IntrinsicInst * findInitTrampolineFromAlloca(Value *TrampMem)
Definition: InstCombineCalls.cpp:2268
llvm::ValueHandleBase::ValueIsRAUWd
static void ValueIsRAUWd(Value *Old, Value *New)
Definition: Value.cpp:1180
llvm::PatternMatch::m_NSWAdd
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1186
llvm::IRBuilderBase::CreateLaunderInvariantGroup
Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1005
llvm::Function::getAttributes
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:249
llvm::InvokeInst
Invoke instruction.
Definition: Instructions.h:3743
llvm::IRBuilderBase::CreateZExt
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2021
llvm::PatternMatch::m_Xor
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1135
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:201
removeTriviallyEmptyRange
static bool removeTriviallyEmptyRange(IntrinsicInst &EndI, InstCombinerImpl &IC, std::function< bool(const IntrinsicInst &)> IsStart)
Definition: InstCombineCalls.cpp:677
llvm::InlineAsm
Definition: InlineAsm.h:31
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:388
llvm::Instruction::andIRFlags
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
Definition: Instruction.cpp:313
llvm::IRBuilderBase::FastMathFlagGuard
Definition: IRBuilder.h:389
VectorUtils.h
llvm::KnownBits::isAllOnes
bool isAllOnes() const
Returns true if value is all one bits.
Definition: KnownBits.h:78
llvm::Use::set
void set(Value *Val)
Definition: Value.h:860
llvm::ConstantExpr::getTrunc
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2083
llvm::GCStatepointInst::getGCRelocates
std::vector< const GCRelocateInst * > getGCRelocates() const
Get list of all gc reloactes linked to this statepoint May contain several relocations for the same b...
Definition: Statepoint.h:214
BasicBlock.h
llvm::cl::opt
Definition: CommandLine.h:1422
llvm::APFloat
Definition: APFloat.h:701
llvm::AttributeList::ReturnIndex
@ ReturnIndex
Definition: Attributes.h:401
llvm::IRBuilderBase::CreateBitCast
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2113
llvm::RetainedKnowledge::AttrKind
Attribute::AttrKind AttrKind
Definition: AssumeBundleQueries.h:102
llvm::PatternMatch::m_Zero
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
Definition: PatternMatch.h:535
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:304
llvm::PatternMatch::m_NUWAdd
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1219
llvm::FunctionType::param_iterator
Type::subtype_iterator param_iterator
Definition: DerivedTypes.h:125
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::isMallocLikeFn
bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such ...
Definition: MemoryBuiltins.cpp:264
llvm::GCRelocateInst
Represents calls to the gc.relocate intrinsic.
Definition: IntrinsicInst.h:1256
findInitTrampoline
static IntrinsicInst * findInitTrampoline(Value *Callee)
Definition: InstCombineCalls.cpp:2328
llvm::PointerType::getUnqual
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:650
llvm::PatternMatch::m_ImmConstant
match_combine_and< class_match< Constant >, match_unless< class_match< ConstantExpr > > > m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
Definition: PatternMatch.h:781
llvm::InlineAsm::canThrow
bool canThrow() const
Definition: InlineAsm.h:71
llvm::LibCallSimplifier
LibCallSimplifier - This class implements a collection of optimizations that replace well formed call...
Definition: SimplifyLibCalls.h:100
llvm::InstCombiner::getAssumptionCache
AssumptionCache & getAssumptionCache() const
Definition: InstCombiner.h:367
llvm::BinaryOperator::CreateFMulFMF
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:268
llvm::BinaryOpIntrinsic::isSigned
bool isSigned() const
Whether the intrinsic is signed or unsigned.
Definition: IntrinsicInst.cpp:527
llvm::InstCombiner::getDataLayout
const DataLayout & getDataLayout() const
Definition: InstCombiner.h:370
llvm::PatternMatch::m_LogicalOr
LogicalOp_match< LHS, RHS, Instruction::Or > m_LogicalOr(const LHS &L, const RHS &R)
Matches L || R either in the form of L | R or L ? true : R.
Definition: PatternMatch.h:2510
llvm::LoadInst::setOrdering
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this load instruction.
Definition: Instructions.h:237
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::TruncInst
This class represents a truncation of integer types.
Definition: Instructions.h:4749
llvm::GCRelocateInst::getDerivedPtr
Value * getDerivedPtr() const
Definition: IntrinsicInst.cpp:572
llvm::AttributeSet::get
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:590
llvm::isStrdupLikeFn
bool isStrdupLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (strdup,...
Definition: MemoryBuiltins.cpp:333
llvm::ConstantPointerNull::get
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1770
llvm::CallBrInst
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
Definition: Instructions.h:3952
llvm::PatternMatch::m_AllOnes
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
Definition: PatternMatch.h:445
simplifyNeonTbl1
static Value * simplifyNeonTbl1(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Convert a table lookup to shufflevector if the mask is constant.
Definition: InstCombineCalls.cpp:621
llvm::Instruction::isIdenticalTo
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one.
Definition: Instruction.cpp:490
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::assumeAligned
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
Definition: Alignment.h:103
llvm::DenseMap< Value *, unsigned >
llvm::InstCombinerImpl::visitFenceInst
Instruction * visitFenceInst(FenceInst &FI)
Definition: InstCombineCalls.cpp:2187
llvm::AtomicOrdering::Unordered
@ Unordered
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::AttrBuilder
Definition: Attributes.h:814
llvm::FunctionType::getParamType
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:134
llvm::LoadInst::setAlignment
void setAlignment(Align Align)
Definition: Instructions.h:227
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::lowerObjectSizeCall
Value * lowerObjectSizeCall(IntrinsicInst *ObjectSize, const DataLayout &DL, const TargetLibraryInfo *TLI, bool MustSucceed)
Try to turn a call to @llvm.objectsize into an integer value of the given Type.
Definition: MemoryBuiltins.cpp:526
llvm::PatternMatch::m_FAbs
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
Definition: PatternMatch.h:2174
llvm::Attribute::getWithDereferenceableBytes
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:176
llvm::PatternMatch::m_And
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1123
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:631
ArrayRef.h
llvm::SimplifyFMAFMul
Value * SimplifyFMAFMul(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for the multiplication of a FMA, fold the result or return null.
Definition: InstructionSimplify.cpp:5078
llvm::Instruction::setDebugLoc
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:369
llvm::PatternMatch::m_SRem
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1111
llvm::computeKnownBits
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
Definition: ValueTracking.cpp:213
maximum
Should compile r2 movcc movcs str strb mov lr r1 movcs movcc mov lr r1 str mov mov cmp r1 movlo r2 str bx lr r0 mov mov cmp r0 movhs r2 mov r1 bx lr Some of the NEON intrinsics may be appropriate for more general either as target independent intrinsics or perhaps elsewhere in the ARM backend Some of them may also be lowered to target independent and perhaps some new SDNodes could be added For maximum
Definition: README.txt:489
llvm::KnownBits::countMaxLeadingZeros
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition: KnownBits.h:264
llvm::Value::MaximumAlignment
static const unsigned MaximumAlignment
Definition: Value.h:785
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
foldClampRangeOfTwo
static Instruction * foldClampRangeOfTwo(IntrinsicInst *II, InstCombiner::BuilderTy &Builder)
If we have a clamp pattern like max (min X, 42), 41 – where the output can only be one of two possibl...
Definition: InstCombineCalls.cpp:760
llvm::KnownBits::countMaxTrailingZeros
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
Definition: KnownBits.h:254
llvm::SPF_ABS
@ SPF_ABS
Floating point maxnum.
Definition: ValueTracking.h:665
llvm::CallBase::hasOperandBundles
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Definition: InstrTypes.h:1901
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:840
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::isKnownNegation
bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW=false)
Return true if the two given values are negation.
Definition: ValueTracking.cpp:5853
llvm::isAlignedAllocLikeFn
bool isAlignedAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates uninitialized memory with a...
Definition: MemoryBuiltins.cpp:277
llvm::Instruction::isFast
bool isFast() const
Determine whether all fast-math-flags are set.
Definition: Instruction.cpp:240
llvm::KnownBits::countMinLeadingZeros
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition: KnownBits.h:234
llvm::KnownBits::countMaxPopulation
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition: KnownBits.h:279
llvm::CmpInst::BAD_ICMP_PREDICATE
@ BAD_ICMP_PREDICATE
Definition: InstrTypes.h:753
APSInt.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:138
llvm::PatternMatch::m_SMin
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1869
simplifyInvariantGroupIntrinsic
static Instruction * simplifyInvariantGroupIntrinsic(IntrinsicInst &II, InstCombinerImpl &IC)
This function transforms launder.invariant.group and strip.invariant.group like: launder(launder(x)) ...
Definition: InstCombineCalls.cpp:400
foldCtpop
static Instruction * foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC)
Definition: InstCombineCalls.cpp:538
llvm::IRBuilderBase::getTrue
ConstantInt * getTrue()
Get the constant value for i1 true.
Definition: IRBuilder.h:458
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::CallBase::Create
static CallBase * Create(CallBase *CB, ArrayRef< OperandBundleDef > Bundles, Instruction *InsertPt=nullptr)
Create a clone of CB with a different set of operand bundles and insert it before InsertPt.
Definition: Instructions.cpp:255
llvm::PatternMatch::m_Constant
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
Definition: PatternMatch.h:142
haveSameOperands
static bool haveSameOperands(const IntrinsicInst &I, const IntrinsicInst &E, unsigned NumOperands)
Definition: InstCombineCalls.cpp:657
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:382
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::PatternMatch::m_Value
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:76
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:70
llvm::User::setOperand
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
llvm::CmpInst::ICMP_SLT
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:749
llvm::APSInt::getMaxValue
static APSInt getMaxValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the maximum integer value with the given bit width and signedness.
Definition: APSInt.h:282
llvm::APIntOps::smin
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
Definition: APInt.h:2168
llvm::PatternMatch::m_SExt
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
Definition: PatternMatch.h:1633
llvm::PatternMatch::m_SpecificInt
specific_intval< false > m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
Definition: PatternMatch.h:885
llvm::ValueHandleBase::ValueIsDeleted
static void ValueIsDeleted(Value *V)
Definition: Value.cpp:1127
llvm::ArrayRef< int >
IT
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
llvm::VAEndInst
This represents the llvm.va_end intrinsic.
Definition: IntrinsicInst.h:1079
llvm::Instruction::getFastMathFlags
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Definition: Instruction.cpp:280
None.h
llvm::APInt::getAllOnesValue
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
Definition: APInt.h:567
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
DataLayout.h
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:212
Cond
SmallVector< MachineOperand, 4 > Cond
Definition: BasicBlockSections.cpp:179
llvm::PatternMatch::m_Undef
auto m_Undef()
Match an arbitrary undef constant.
Definition: PatternMatch.h:136
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
SimplifyLibCalls.h
llvm::CmpInst::ICMP_ULT
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:745
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Constant::getAggregateElement
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Definition: Constants.cpp:420
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
isSafeToEliminateVarargsCast
static bool isSafeToEliminateVarargsCast(const CallBase &Call, const DataLayout &DL, const CastInst *const CI, const int ix)
If this cast does not affect the value passed through the varargs area, we can eliminate the use of t...
Definition: InstCombineCalls.cpp:2208
llvm::Instruction::getFunction
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:70
llvm::PatternMatch::m_Shuffle
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
Definition: PatternMatch.h:1561
uint32_t
Compiler.h
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:979
llvm::InstCombinerImpl::visitVAEndInst
Instruction * visitVAEndInst(VAEndInst &I)
Definition: InstCombineCalls.cpp:704
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:81
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::CastInst::isBitOrNoopPointerCastable
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op.
Definition: Instructions.cpp:3300
llvm::ConstantExpr::getIntegerCast
static Constant * getIntegerCast(Constant *C, Type *Ty, bool IsSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:2059
llvm::RecurKind::Mul
@ Mul
Product of integers.
llvm::FPExtInst
This class represents an extension of floating point types.
Definition: Instructions.h:4905
trunc
We have fiadd patterns now but the followings have the same cost and complexity We need a way to specify the later is more profitable def def The FP stackifier should handle simple permutates to reduce number of shuffle e g trunc
Definition: README-FPStack.txt:63
llvm::RetainedKnowledge
Represent one information held inside an operand bundle of an llvm.assume.
Definition: AssumeBundleQueries.h:101
llvm::Instruction::copyFastMathFlags
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
Definition: Instruction.cpp:235
llvm::CastInst
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:430
llvm::WithOverflowInst
Represents an op.with.overflow intrinsic.
Definition: IntrinsicInst.h:567
llvm::AMDGPUISD::BFI
@ BFI
Definition: AMDGPUISelLowering.h:421
llvm::APInt::ult
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition: APInt.h:1205
llvm::Attribute::getWithDereferenceableOrNullBytes
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:182
llvm::CallBase::hasRetAttr
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
Definition: InstrTypes.h:1577
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:273
llvm::PatternMatch::m_SMax
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
Definition: PatternMatch.h:1863
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:297
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:127
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:175
llvm::isOpNewLikeFn
bool isOpNewLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory and throws if an all...
Definition: MemoryBuiltins.cpp:326
ValueHandle.h
llvm::BasicBlock::getTerminator
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:148
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:675
llvm::SmallPtrSetImplBase::size
size_type size() const
Definition: SmallPtrSet.h:92
llvm::CallBase::doesNotThrow
bool doesNotThrow() const
Determine if the call cannot unwind.
Definition: InstrTypes.h:1845
llvm::OperandBundleUse::Inputs
ArrayRef< Use > Inputs
Definition: InstrTypes.h:1057
llvm::ConstantInt::getZExtValue
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:142
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:206
getPromotedType
static Type * getPromotedType(Type *Ty)
Return the specified type promoted as it would be to pass though a va_arg area.
Definition: InstCombineCalls.cpp:103
llvm::Attribute::getWithAlignment
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:166
llvm::GetStringLength
uint64_t GetStringLength(const Value *V, unsigned CharSize=8)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'.
Definition: ValueTracking.cpp:4289
llvm::Function::doesNotThrow
bool doesNotThrow() const
Determine if the function cannot unwind.
Definition: Function.h:608
Attributes.h
llvm::PatternMatch::m_FPExt
CastClass_match< OpTy, Instruction::FPExt > m_FPExt(const OpTy &Op)
Definition: PatternMatch.h:1697
llvm::APIntOps::umax
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
Definition: APInt.h:2183
Constant.h
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition: NVPTX.h:123
llvm::GCRelocateInst::getBasePtr
Value * getBasePtr() const
Definition: IntrinsicInst.cpp:566
llvm::minnum
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
Definition: APFloat.h:1298
llvm::IRBuilderBase::getFalse
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition: IRBuilder.h:463
llvm::APInt::uadd_sat
APInt uadd_sat(const APInt &RHS) const
Definition: APInt.cpp:2051
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:204
llvm::ConstantInt::getTrue
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:847
llvm::Constant::getNullValue
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:346
llvm::KnownBits
Definition: KnownBits.h:23
llvm::ConstantExpr::getNeg
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2659
llvm::AnyMemSetInst
This class represents any memset intrinsic.
Definition: IntrinsicInst.h:988
llvm::CastInst::CreateBitOrPointerCast
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
Definition: Instructions.cpp:3195
llvm::KnownBits::countMinPopulation
unsigned countMinPopulation() const
Returns the number of bits known to be one.
Definition: KnownBits.h:274
NC
#define NC
Definition: regutils.h:42
llvm::BinaryOperator::CreateNUW
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:303
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::ConstantInt::getBool
static ConstantInt * getBool(LLVMContext &Context, bool V)
Definition: Constants.cpp:861
llvm::Type::isIntOrIntVectorTy
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:207
GlobalVariable.h
llvm::ConstantFP::get
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:946
Casting.h
llvm::InstCombinerImpl::visitCallBrInst
Instruction * visitCallBrInst(CallBrInst &CBI)
Definition: InstCombineCalls.cpp:2202
LowAndHigh
Metadata * LowAndHigh[]
Definition: NVVMIntrRange.cpp:68
Function.h
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::BinaryOperator::CreateNSWNeg
static BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Definition: Instructions.cpp:2670
llvm::DenseMapBase::size
unsigned size() const
Definition: DenseMap.h:100
llvm::PatternMatch::m_BSwap
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
Definition: PatternMatch.h:2169
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:219
powi
This is blocked on not handling X *X *X powi(X, 3)(see note above). The issue is that we end up getting t
llvm::OverflowResult::AlwaysOverflowsHigh
@ AlwaysOverflowsHigh
Always overflows in the direction of signed/unsigned max value.
llvm::Function::getFunctionType
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:175
llvm::PatternMatch::m_ZeroInt
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
Definition: PatternMatch.h:522
llvm::getInverseMinMaxIntrinsic
Intrinsic::ID getInverseMinMaxIntrinsic(Intrinsic::ID MinMaxID)
Definition: ValueTracking.cpp:6242
llvm::PatternMatch::m_PtrToInt
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
Definition: PatternMatch.h:1609
llvm::Instruction::hasAllowReassoc
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
Definition: Instruction.cpp:245
llvm::CallBase::getCalledOperand
Value * getCalledOperand() const
Definition: InstrTypes.h:1386
createOverflowTuple
static Instruction * createOverflowTuple(IntrinsicInst *II, Value *Result, Constant *Overflow)
Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value...
Definition: InstCombineCalls.cpp:725
llvm::IntrinsicInst
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:45
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::APInt::isNullValue
bool isNullValue() const
Determine if all bits are clear.
Definition: APInt.h:411
llvm::InstCombinerImpl::replaceOperand
Instruction * replaceOperand(Instruction &I, unsigned OpNum, Value *V)
Replace operand of instruction and add old operand to the worklist.
Definition: InstCombineInternal.h:419
llvm::BasicBlock::reverse_iterator
InstListType::reverse_iterator reverse_iterator
Definition: BasicBlock.h:92
llvm::RecurKind::FAdd
@ FAdd
Sum of floats.
Instructions.h
llvm::isImpliedByDomCondition
Optional< bool > isImpliedByDomCondition(const Value *Cond, const Instruction *ContextI, const DataLayout &DL)
Return the boolean condition value in the context of the given instruction if it is known based on do...
Definition: ValueTracking.cpp:6657
llvm::Type::isStructTy
bool isStructTy() const
True if this is an instance of StructType.
Definition: Type.h:222
llvm::AttributeSet
Definition: Attributes.h:266
SmallVector.h
getKnownSign
static Optional< bool > getKnownSign(Value *Op, Instruction *CxtI, const DataLayout &DL, AssumptionCache *AC, DominatorTree *DT)
Definition: InstCombineCalls.cpp:744
llvm::PatternMatch::m_Specific
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Definition: PatternMatch.h:802
User.h
llvm::PatternMatch::m_ICmp
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Definition: PatternMatch.h:1404
llvm::CmpInst::ICMP_UGT
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:743
llvm::User::op_begin
op_iterator op_begin()
Definition: User.h:234
llvm::Type::getPointerElementType
Type * getPointerElementType() const
Definition: Type.h:380
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1338
SmallBitVector.h
N
#define N
llvm::IntrinsicInst::isCommutative
bool isCommutative() const
Return true if swapping the first two arguments to the intrinsic produces the same result.
Definition: IntrinsicInst.h:58
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:94
InstructionSimplify.h
llvm::ConstantExpr::getMul
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2700
TargetTransformInfo.h
llvm::PHINode
Definition: Instructions.h:2627
llvm::Instruction::copyIRFlags
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
Definition: Instruction.cpp:289
llvm::buildAssumeFromKnowledge
AssumeInst * buildAssumeFromKnowledge(ArrayRef< RetainedKnowledge > Knowledge, Instruction *CtxI, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr)
Build and return a new assume created from the provided knowledge if the knowledge in the assume is f...
Definition: AssumeBundleBuilder.cpp:307
llvm::CallBase::addAttribute
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: InstrTypes.h:1489
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:271
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:401
DerivedTypes.h
llvm::PatternMatch::m_Neg
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
Definition: PatternMatch.h:2264
llvm::APInt::getLowBitsSet
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Definition: APInt.h:667
llvm::IntegerType::get
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:275
llvm::TargetLibraryInfoImpl::isCallingConvCCompatible
static bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
Definition: TargetLibraryInfo.cpp:101
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1475
llvm::X86AS::SS
@ SS
Definition: X86.h:189
LLVMContext.h
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::IRBuilderBase::CreateSub
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1225
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:370
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::InstCombinerImpl::SimplifyAnyMemSet
Instruction * SimplifyAnyMemSet(AnyMemSetInst *MI)
Definition: InstCombineCalls.cpp:226
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::cl::desc
Definition: CommandLine.h:414
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
raw_ostream.h
llvm::PatternMatch::m_Trunc
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
Definition: PatternMatch.h:1621
llvm::NullPointerIsDefined
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Definition: Function.cpp:1925
llvm::Attribute::getWithByValType
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:188
llvm::ConstantAggregateZero::get
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1663
llvm::Type::canLosslesslyBitCastTo
bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
Definition: Type.cpp:69
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:624
llvm::isPowerOf2_64
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:496
Value.h
llvm::abs
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition: APFloat.h:1284
llvm::PatternMatch::m_Cmp
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
Definition: PatternMatch.h:89
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition: DerivedTypes.h:123
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
Debug.h
llvm::Value::users
iterator_range< user_iterator > users()
Definition: Value.h:422
llvm::InstCombinerImpl::computeKnownBits
void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
Definition: InstCombineInternal.h:463
llvm::APIntOps::smax
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
Definition: APInt.h:2173
llvm::AttributeList::isEmpty
bool isEmpty() const
Return true if there are no attributes.
Definition: Attributes.h:775
llvm::PatternMatch::m_LogicalAnd
LogicalOp_match< LHS, RHS, Instruction::And > m_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R either in the form of L & R or L ? R : false.
Definition: PatternMatch.h:2499
llvm::IRBuilderBase::CreateCall
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2391
llvm::Optional::getValue
constexpr const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:282
llvm::isFreeCall
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
Definition: MemoryBuiltins.cpp:487
llvm::Instruction::moveBefore
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Definition: Instruction.cpp:97
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1172
llvm::CallBase::setCallingConv
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1453
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:102
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:364
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1803