Skip to content

Commit

Permalink
[VP] vp intrinsics are not speculatable
Browse files Browse the repository at this point in the history
VP intrinsics show UB if the %evl parameter is out of bounds - they must
not carry the speculatable attribute.  The out-of-bounds UB disappears
when the %evl parameter is expanded into the mask or expansion replaces
the entire VP intrinsic with non-VP code.

This patch
- Removes the speculatable attribute on all VP intrinsics.
- Generalizes the isSafeToSpeculativelyExecute function to let VP
  expansion know whether the VP intrinsic replacement will be
  speculatable.  VP expansion may only discard %evl where this is the
  case.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D125296
  • Loading branch information
simoll committed May 30, 2022
1 parent 180d3f2 commit 78a18d2
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 205 deletions.
22 changes: 22 additions & 0 deletions llvm/include/llvm/Analysis/ValueTracking.h
Expand Up @@ -463,6 +463,28 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr);

/// This returns the same result as isSafeToSpeculativelyExecute if Opcode is
/// the actual opcode of Inst. If the provided and actual opcode differ, the
/// function (virtually) overrides the opcode of Inst with the provided
/// Opcode. There are come constraints in this case:
/// * If Opcode has a fixed number of operands (eg, as binary operators do),
/// then Inst has to have at least as many leading operands. The function
/// will ignore all trailing operands beyond that number.
/// * If Opcode allows for an arbitrary number of operands (eg, as CallInsts
/// do), then all operands are considered.
/// * The virtual instruction has to satisfy all typing rules of the provided
/// Opcode.
/// * This function is pessimistic in the following sense: If one actually
/// materialized the virtual instruction, then isSafeToSpeculativelyExecute
/// may say that the materialized instruction is speculatable whereas this
/// function may have said that the instruction wouldn't be speculatable.
/// This behavior is a shortcoming in the current implementation and not
/// intentional.
bool isSafeToSpeculativelyExecuteWithOpcode(
unsigned Opcode, const Operator *Inst, const Instruction *CtxI = nullptr,
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr);

/// Returns true if the result or effects of the given instructions \p I
/// depend values not reachable through the def use graph.
/// * Memory dependence arises for example if the instruction reads from
Expand Down

0 comments on commit 78a18d2

Please sign in to comment.