Skip to content

Commit d11a719

Browse files
authored
Revert "[IR] Reject unhandled assume bundles and seperate them from normal attributes" (#202336)
Reverts #197007 This causes an assertion failure.
1 parent 3f5c25f commit d11a719

23 files changed

Lines changed: 684 additions & 593 deletions

File tree

llvm/docs/LangRef.rst

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,6 @@ Currently, only the following parameter attributes are defined:
15871587
:ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
15881588
return values and can only be applied to one parameter.
15891589

1590-
.. _attr_nonnull:
1591-
15921590
``nonnull``
15931591
This indicates that the parameter or return pointer is not null. This
15941592
attribute may only be applied to pointer-typed parameters. This is not
@@ -1600,8 +1598,6 @@ Currently, only the following parameter attributes are defined:
16001598
The ``nonnull`` attribute should be combined with the ``noundef`` attribute
16011599
to ensure a pointer is not null or otherwise the behavior is undefined.
16021600

1603-
.. _attr_dereferenceable:
1604-
16051601
``dereferenceable(<n>)``
16061602
This indicates that the parameter or return pointer is dereferenceable. This
16071603
attribute may only be applied to pointer-typed parameters. A pointer that
@@ -1614,9 +1610,9 @@ Currently, only the following parameter attributes are defined:
16141610
``null_pointer_is_valid`` function attribute is present.
16151611
``n`` should be a positive number. The pointer should be well defined,
16161612
otherwise it is undefined behavior. This means ``dereferenceable(<n>)``
1617-
implies ``noundef``.
1618-
1619-
.. _attr_dereferenceable_or_null:
1613+
implies ``noundef``. When used in an assume operand bundle, more restricted
1614+
semantics apply. See :ref:`assume operand bundles <assume_opbundles>` for
1615+
more details.
16201616

16211617
``dereferenceable_or_null(<n>)``
16221618
This indicates that the parameter or return value isn't both
@@ -1671,8 +1667,6 @@ Currently, only the following parameter attributes are defined:
16711667
only valid on intrinsic declarations and cannot be applied to a
16721668
call site or arbitrary function.
16731669

1674-
.. _attr_noundef:
1675-
16761670
``noundef``
16771671
This attribute applies to parameters and return values. If the value
16781672
representation contains any undefined or poison bits, the behavior is
@@ -2155,9 +2149,6 @@ For example:
21552149
uses the ``nobuiltin`` attribute. This is only valid at call sites for
21562150
direct calls to functions that are declared with the ``nobuiltin``
21572151
attribute.
2158-
2159-
.. _attr_cold:
2160-
21612152
``cold``
21622153
This attribute indicates that this function is rarely called. When
21632154
computing edge weights, basic blocks post-dominated by a cold
@@ -3136,57 +3127,33 @@ Assume Operand Bundles
31363127
^^^^^^^^^^^^^^^^^^^^^^
31373128

31383129
Operand bundles on an :ref:`llvm.assume <int_assume>` allow representing
3139-
assumptions that hold at the location of the assume. Operand bundles enable
3140-
assumptions that are either hard or impossible to represent as a boolean
3141-
argument of an :ref:`llvm.assume <int_assume>`.
3130+
assumptions, such as that a :ref:`parameter attribute <paramattrs>` or a
3131+
:ref:`function attribute <fnattrs>` holds for a certain value at a certain
3132+
location. Operand bundles enable assumptions that are either hard or impossible
3133+
to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`.
31423134

31433135
Assumes with operand bundles must have ``i1 true`` as the condition operand.
31443136

3145-
Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the
3146-
provided guarantees are violated at runtime the behavior is undefined.
3137+
An assume operand bundle has the form:
31473138

3148-
While attributes expect constant arguments, assume operand bundles may be
3149-
provided a dynamic value, for example:
3150-
3151-
.. code-block:: llvm
3152-
3153-
call void @llvm.assume(i1 true) ["align"(ptr %val, i32 %align)]
3154-
3155-
The following attributes are currently accepted:
3156-
3157-
``"align"(ptr %p, i64 %align)``, ``"align"(ptr %p, i64 %align, i64 %offset)``
3158-
Equivalent to :ref:`align(%align) <attr_align>` on ``%p``, or ``%p - %offset``
3159-
if the ``%offset`` argument exists, except that ``%align`` may be a
3160-
non-power-of-two alignment (including a zero alignment). If ``%align`` is not
3161-
a power of two the pointer value must be all-zero. Otherwise the behavior is
3162-
undefined.
3163-
3164-
``"cold"()``
3165-
Equivalent to :ref:`cold <attr_cold>`.
3139+
::
31663140

3167-
``"dereferenceable"(ptr %p, i64 %size)``
3168-
Equivalent to :ref:`dereferenceable(%size) <attr_dereferenceable>` on ``%p``,
3169-
except that ``%size`` may also be zero, in which case the bundle doesn't
3170-
imply ``nonnull``.
3141+
"<tag>"([ <arguments>] ])
31713142

3172-
``"dereferenceable_or_null"(ptr %p, i64 %size)``
3173-
Equivalent to :ref:`dereferenceable_or_null(%size)
3174-
<attr_dereferenceable_or_null>` on ``%p``, except that ``%size`` may also be
3175-
zero.
3143+
In the case of function or parameter attributes, the operand bundle has the
3144+
restricted form:
31763145

3177-
``"ignore"(...)``
3178-
Doesn't imply anything and is ignored. This is used to drop an assume where
3179-
the ``llvm.assume`` call cannot be replaced or dropped.
3146+
::
31803147

3181-
``"nonnull"(ptr %p)``
3182-
Equivalent to :ref:`nonnull <attr_nonnull>` on ``%p``.
3148+
"<tag>"([ <holds for value> [, <attribute argument>] ])
31833149

3184-
``"noundef"(any_type %v)``
3185-
Equivalent to :ref:`noundef <attr_noundef>` on ``%v``.
3150+
* The tag of the operand bundle is usually the name of the attribute that can be
3151+
assumed to hold. It can also be `ignore`; this tag doesn't contain any
3152+
information and should be ignored.
3153+
* The first argument, if present, is the value for which the attribute holds.
3154+
* The second argument, if present, is an argument of the attribute.
31863155

3187-
``"separate_storage"(ptr %p1, ptr %p2)``
3188-
This indicates that no pointer :ref:`based <pointeraliasing>` on one of its
3189-
arguments can alias any pointer based on the other.
3156+
If there are no arguments the attribute is a property of the call location.
31903157

31913158
For example:
31923159

@@ -3204,6 +3171,39 @@ allows the optimizer to assume that at location of call to
32043171
allows the optimizer to assume that the :ref:`llvm.assume <int_assume>`
32053172
call location is cold and that ``%val`` may not be null.
32063173

3174+
Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the
3175+
provided guarantees are violated at runtime the behavior is undefined.
3176+
3177+
While attributes expect constant arguments, assume operand bundles may be
3178+
provided a dynamic value, for example:
3179+
3180+
.. code-block:: llvm
3181+
3182+
call void @llvm.assume(i1 true) ["align"(ptr %val, i32 %align)]
3183+
3184+
If the operand bundle value violates any requirements on the attribute value,
3185+
the behavior is undefined, unless one of the following exceptions applies:
3186+
3187+
* ``"align"`` operand bundles may specify a non-power-of-two alignment
3188+
(including a zero alignment). If this is the case, then the pointer value
3189+
must be an all-zero pointer, otherwise the behavior is undefined.
3190+
3191+
* ``dereferenceable(<n>)`` operand bundles only guarantee the pointer is
3192+
dereferenceable at the point of the assumption. The pointer may not be
3193+
dereferenceable at later pointers, e.g., because it could have been freed.
3194+
Only ``n > 0`` implies that the pointer is dereferenceable.
3195+
3196+
In addition to allowing operand bundles encoding function and parameter
3197+
attributes, an assume operand bundle may also encode a ``separate_storage``
3198+
operand bundle. This has the form:
3199+
3200+
.. code-block:: llvm
3201+
3202+
separate_storage(<val1>, <val2>)``
3203+
3204+
This indicates that no pointer :ref:`based <pointeraliasing>` on one of its
3205+
arguments can alias any pointer based on the other.
3206+
32073207
Even if the assumed property can be encoded as a boolean value, like
32083208
``nonnull``, using operand bundles to express the property can still have
32093209
benefits:
@@ -8143,7 +8143,7 @@ Together these two attributes provide a four-way classification:
81438143

81448144
- ``body`` only: main vectorized loop body
81458145
- ``epilogue`` only: scalar epilogue loop after vectorization
8146-
- Both ``body`` and ``epilogue``: vectorized epilogue
8146+
- Both ``body`` and ``epilogue``: vectorized epilogue
81478147
(a remainder loop that was itself vectorized during epilogue
81488148
vectorization)
81498149
- Neither: a plain loop not produced by the vectorizer
@@ -8772,7 +8772,7 @@ is executed, followed by ``uint64_t`` value and execution count pairs.
87728772
The value profiling kind is 0 for indirect call targets and 1 for memory
87738773
operations. For indirect call targets, each profile value is a hash
87748774
of the callee function name, and for memory operations each value is the
8775-
byte length. It is illegal to have duplicate profile values (e.g.,
8775+
byte length. It is illegal to have duplicate profile values (e.g.,
87768776
duplicate function hashes for indirect calls or byte lengths for memory
87778777
operations).
87788778

llvm/docs/ReleaseNotes.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ Makes programs 10x faster by doing Special New Thing.
8787
and `ccc` agree for `void(ptr)` (x86_64, AArch64, RISC-V, ...) but is an ABI
8888
break on i686, MIPS O32, PowerPC64 ELFv1, and Lanai.
8989

90-
* Assume bundles now only accept attributes that are actually handled.
91-
Specifically, they are ``align``, ``cold``, ``dereferenceable``,
92-
``dereferenceable_or_null``, ``nonnull``, ``noundef`` and
93-
``separate_storage``.
94-
9590
* Fast math flags are now permitted on `uitofp` and `sitofp`.
9691

9792
### Changes to LLVM infrastructure

llvm/include/llvm/IR/BundleAttributes.def

Lines changed: 0 additions & 22 deletions
This file was deleted.

llvm/include/llvm/IR/BundleAttributes.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,12 +2353,6 @@ class CallBase : public Instruction {
23532353
return make_range(bundle_op_info_begin(), bundle_op_info_end());
23542354
}
23552355

2356-
auto operand_bundles() const {
2357-
return map_range(bundle_op_infos(), [this](BundleOpInfo BOI) {
2358-
return operandBundleFromBundleOpInfo(BOI);
2359-
});
2360-
}
2361-
23622356
/// Populate the BundleOpInfo instances and the Use& vector from \p
23632357
/// Bundles. Return the op_iterator pointing to the Use& one past the last
23642358
/// last bundle operand use.

llvm/include/llvm/Transforms/Utils/PredicateInfo.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
#include "llvm/ADT/DenseMap.h"
5454
#include "llvm/ADT/SmallSet.h"
55-
#include "llvm/IR/BundleAttributes.h"
5655
#include "llvm/IR/Instructions.h"
5756
#include "llvm/IR/PassManager.h"
5857
#include "llvm/IR/ValueHandle.h"
@@ -133,9 +132,9 @@ class PredicateAssume : public PredicateBase {
133132

134133
class PredicateBundleAssume : public PredicateAssume {
135134
public:
136-
BundleAttr AttrKind;
135+
Attribute::AttrKind AttrKind;
137136
PredicateBundleAssume(Value *Op, IntrinsicInst *AssumeInst,
138-
BundleAttr AttrKind)
137+
Attribute::AttrKind AttrKind)
139138
: PredicateAssume(PT_BundleAssume, Op, AssumeInst, nullptr),
140139
AttrKind(AttrKind) {}
141140

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/Analysis/LazyValueInfo.h"
1515
#include "llvm/ADT/DenseSet.h"
1616
#include "llvm/ADT/STLExtras.h"
17+
#include "llvm/Analysis/AssumeBundleQueries.h"
1718
#include "llvm/Analysis/AssumptionCache.h"
1819
#include "llvm/Analysis/ConstantFolding.h"
1920
#include "llvm/Analysis/InstructionSimplify.h"
@@ -22,7 +23,6 @@
2223
#include "llvm/Analysis/ValueLattice.h"
2324
#include "llvm/Analysis/ValueTracking.h"
2425
#include "llvm/IR/AssemblyAnnotationWriter.h"
25-
#include "llvm/IR/BundleAttributes.h"
2626
#include "llvm/IR/CFG.h"
2727
#include "llvm/IR/ConstantRange.h"
2828
#include "llvm/IR/Constants.h"
@@ -856,24 +856,26 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
856856
continue;
857857

858858
if (AssumeVH.Index != AssumptionCache::ExprResultIdx) {
859-
auto OBU = I->getOperandBundleAt(AssumeVH.Index);
860-
switch (getBundleAttrFromOBU(OBU)) {
861-
case BundleAttr::NonNull:
862-
assert(getAssumeNonNullInfo(OBU).Ptr == Val);
863-
BBLV = BBLV.intersect(ValueLatticeElement::getNot(
864-
Constant::getNullValue(Val->getType())));
865-
break;
866-
867-
case BundleAttr::Dereferenceable: {
868-
auto [Ptr, Count] = getAssumeDereferenceableInfo(OBU);
869-
assert(Ptr == Val);
870-
if (auto *CI = dyn_cast<ConstantInt>(Count); CI && !CI->isZero())
859+
if (RetainedKnowledge RK = getKnowledgeFromBundle(
860+
*I, I->bundle_op_info_begin()[AssumeVH.Index])) {
861+
if (RK.WasOn != Val)
862+
continue;
863+
switch (RK.AttrKind) {
864+
case Attribute::NonNull:
871865
BBLV = BBLV.intersect(ValueLatticeElement::getNot(
872-
Constant::getNullValue(Val->getType())));
873-
} break;
866+
Constant::getNullValue(RK.WasOn->getType())));
867+
break;
874868

875-
default:
876-
break;
869+
case Attribute::Dereferenceable:
870+
if (auto *CI = dyn_cast<ConstantInt>(RK.IRArgValue);
871+
CI && !CI->isZero())
872+
BBLV = BBLV.intersect(ValueLatticeElement::getNot(
873+
Constant::getNullValue(RK.WasOn->getType())));
874+
break;
875+
876+
default:
877+
break;
878+
}
877879
}
878880
} else {
879881
BBLV = BBLV.intersect(*getValueFromCondition(Val, I->getArgOperand(0),

0 commit comments

Comments
 (0)