Skip to content

Commit e56c2ce

Browse files
authored
[IR] Remove llvm.strip.invariant.group intrinsic (#225399)
This intrinsic was originally introduced to make sure that if we have a dominating condition like `a == launder.invariant.group(a)`, we don't end up replacing the latter with the former, as that would allow the optimizer to assume that the memory stays invariant, despite going through a launder operation. Wrapping both comparison operands in strip.invariant.group avoids the issue, because replacing one stripped pointer with another is safe. The underlying issue was fixed in #224281 (and prior work), which ensures that the problematic replacement cannot happen in the first place. #225072 stopped emitting llvm.strip.invariant.group on the clang side. This PR now removes the intrinsic entirely. To be on the safe side, it is upgraded to llvm.launder.invariant.group. For Clang's specific usage, just dropping it would be fine.
1 parent 7ecac80 commit e56c2ce

61 files changed

Lines changed: 175 additions & 716 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎llvm/docs/LangRef.md‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24340,36 +24340,6 @@ Returns another pointer that aliases its argument but which is considered differ
2434024340
for the purposes of `load`/`store` `invariant.group` metadata.
2434124341
It does not read any accessible memory and the execution can be speculated.
2434224342

24343-
#### '`llvm.strip.invariant.group`' Intrinsic
24344-
24345-
##### Syntax:
24346-
This is an overloaded intrinsic. The {ref}`allocated object<allocatedobjects>`
24347-
can belong to any address space. The returned pointer must belong to the same
24348-
address space as the argument.
24349-
24350-
```
24351-
declare ptr @llvm.strip.invariant.group.p0(ptr <ptr>)
24352-
```
24353-
24354-
##### Overview:
24355-
24356-
The '`llvm.strip.invariant.group`' intrinsic can be used when an invariant
24357-
established by `invariant.group` metadata no longer holds, to obtain a new pointer
24358-
value that does not carry the invariant information. It is an experimental
24359-
intrinsic, which means that its semantics might change in the future.
24360-
24361-
24362-
##### Arguments:
24363-
24364-
The `llvm.strip.invariant.group` takes only one argument, which is a pointer
24365-
to the memory.
24366-
24367-
##### Semantics:
24368-
24369-
Returns another pointer that aliases its argument but which has no associated
24370-
`invariant.group` metadata.
24371-
It does not read any memory and can be speculated.
24372-
2437324343

2437424344

2437524345
(constrainedfp)=

‎llvm/docs/ReleaseNotes.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ Makes programs 10x faster by doing Special New Thing.
161161
The `llvm.vp.merge` will be folded away but the `%evl` will be propagated to
162162
the add instruction.
163163

164+
* The `llvm.strip.invariant.group` intrinsic has been removed. It existed to
165+
work around a bug relating to replacement of pointers with different
166+
provenance based on dominating equality conditions, and is no longer needed.
167+
164168
* Introduced the generic `!atomic.ignore.denormal.mode` metadata for
165169
floating-point `atomicrmw` instructions, generalizing the previously
166170
AMDGPU-specific `!amdgpu.ignore.denormal.mode`.

‎llvm/include/llvm/Analysis/TargetTransformInfoImpl.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,6 @@ class LLVM_ABI TargetTransformInfoImplBase {
940940
case Intrinsic::invariant_start:
941941
case Intrinsic::invariant_end:
942942
case Intrinsic::launder_invariant_group:
943-
case Intrinsic::strip_invariant_group:
944943
case Intrinsic::is_constant:
945944
case Intrinsic::lifetime_start:
946945
case Intrinsic::lifetime_end:

‎llvm/include/llvm/Analysis/ValueTracking.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ getArgumentAliasingToReturnedPointer(CallBase *Call, bool MustPreserveOffset,
451451
MustPreserveProvenance));
452452
}
453453

454-
/// {launder,strip}.invariant.group returns pointer that aliases its argument,
455-
/// and it only captures pointer by returning it.
454+
/// launder.invariant.group and similar intrinsics return a pointer that
455+
/// aliases their argument, and only capture the pointer by returning it.
456456
/// These intrinsics are not marked as nocapture, because returning is
457457
/// considered as capture. The arguments are not marked as returned neither,
458458
/// because it would make it useless. See getArgumentAliasingToReturnedPointer()

‎llvm/include/llvm/IR/IRBuilder.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,11 +2789,6 @@ class IRBuilderBase {
27892789
/// address space before call and casted back to Ptr type after call.
27902790
LLVM_ABI Value *CreateLaunderInvariantGroup(Value *Ptr);
27912791

2792-
/// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2793-
/// different from pointer to i8, it's casted to pointer to i8 in the same
2794-
/// address space before call and casted back to Ptr type after call.
2795-
LLVM_ABI Value *CreateStripInvariantGroup(Value *Ptr);
2796-
27972792
/// Return a vector value that contains the vector V reversed
27982793
LLVM_ABI Value *CreateVectorReverse(Value *V, const Twine &Name = "");
27992794

‎llvm/include/llvm/IR/Instruction.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,6 @@ class Instruction : public User,
951951
/// llvm.lifetime.end marker.
952952
LLVM_ABI bool isLifetimeStartOrEnd() const LLVM_READONLY;
953953

954-
/// Return true if the instruction is a llvm.launder.invariant.group or
955-
/// llvm.strip.invariant.group.
956-
LLVM_ABI bool isLaunderOrStripInvariantGroup() const LLVM_READONLY;
957-
958954
/// Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
959955
LLVM_ABI bool isDebugOrPseudoInst() const LLVM_READONLY;
960956

‎llvm/include/llvm/IR/Intrinsics.td‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,11 +1918,6 @@ def int_launder_invariant_group : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
19181918
[IntrInaccessibleMemOnly,
19191919
IntrSpeculatable]>;
19201920

1921-
1922-
def int_strip_invariant_group : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
1923-
[LLVMMatchType<0>],
1924-
[IntrSpeculatable, IntrNoMem]>;
1925-
19261921
//===------------------------ Stackmap Intrinsics -------------------------===//
19271922
//
19281923
def int_experimental_stackmap : DefaultAttrsIntrinsic<[],

‎llvm/include/llvm/IR/Value.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class Value {
685685
/// accumulated even if the GEP is not "inbounds".
686686
///
687687
/// If \p AllowInvariantGroup is true then this method also looks through
688-
/// strip.invariant.group and launder.invariant.group intrinsics.
688+
/// launder.invariant.group intrinsics.
689689
///
690690
/// If \p ExternalAnalysis is provided it will be used to calculate a offset
691691
/// when a operand of GEP is not constant.

‎llvm/lib/Analysis/ConstantFolding.cpp‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,6 @@ static bool canConstantFoldIntrinsic(Intrinsic::ID ID, bool IsStrictFP) {
17461746
case Intrinsic::pdep:
17471747
case Intrinsic::pext:
17481748
case Intrinsic::launder_invariant_group:
1749-
case Intrinsic::strip_invariant_group:
17501749
case Intrinsic::masked_load:
17511750
case Intrinsic::get_active_lane_mask:
17521751
case Intrinsic::abs:
@@ -2634,15 +2633,13 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
26342633
return Constant::getNullValue(Ty);
26352634
if (IntrinsicID == Intrinsic::bswap ||
26362635
IntrinsicID == Intrinsic::bitreverse ||
2637-
IntrinsicID == Intrinsic::launder_invariant_group ||
2638-
IntrinsicID == Intrinsic::strip_invariant_group)
2636+
IntrinsicID == Intrinsic::launder_invariant_group)
26392637
return Operands[0];
26402638
}
26412639

26422640
if (isa<ConstantPointerNull>(Operands[0])) {
2643-
// launder(null) == null == strip(null) iff in addrspace 0
2644-
if (IntrinsicID == Intrinsic::launder_invariant_group ||
2645-
IntrinsicID == Intrinsic::strip_invariant_group) {
2641+
// launder(null) == null iff in addrspace 0
2642+
if (IntrinsicID == Intrinsic::launder_invariant_group) {
26462643
// If instruction is not yet put in a basic block (e.g. when cloning
26472644
// a function during inlining), Call's caller may not be available.
26482645
// So check Call's BB first before querying Call->getCaller.

‎llvm/lib/Analysis/InlineCost.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,6 @@ bool CallAnalyzer::visitCallBase(CallBase &Call) {
25352535
InitsVargArgs = true;
25362536
return false;
25372537
case Intrinsic::launder_invariant_group:
2538-
case Intrinsic::strip_invariant_group:
25392538
if (auto *SROAArg = getSROAArgForValueOrNull(II->getOperand(0)))
25402539
SROAArgValues[II] = SROAArg;
25412540
return true;

0 commit comments

Comments
 (0)