[llvm] [InstCombine] Remove redundant alignment assumptions. (PR #123348)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 1 12:51:14 PDT 2025
================
@@ -3245,6 +3246,30 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
MaybeSimplifyHint(OBU.Inputs[0]);
MaybeSimplifyHint(OBU.Inputs[1]);
}
+
+ // Try to fold alignment assumption into a load's !align metadata, if the
+ // assumption is valid in the load's context and remove redundant ones.
+ if (OBU.getTagName() == "align" && OBU.Inputs.size() == 2) {
+ RetainedKnowledge RK = getKnowledgeFromBundle(
+ *cast<AssumeInst>(II), II->bundle_op_info_begin()[Idx]);
+ if (!RK || RK.AttrKind != Attribute::Alignment ||
+ !isPowerOf2_64(RK.ArgValue))
+ continue;
+
+ // Don't try to remove align assumptions for pointers derived from
+ // arguments. We might lose information if the function gets inline and
+ // the align argument attribute disappears.
+ Value *UO = getUnderlyingObject(RK.WasOn);
+ if (!UO || isa<Argument>(UO))
+ continue;
+
+ KnownBits Known = computeKnownBits(RK.WasOn, 0, nullptr);
----------------
nikic wrote:
Yes. We set AllowEphemerals=true there on the assumption that known bits won't be used to remove align operand bundles -- which is no longer true.
https://github.com/llvm/llvm-project/pull/123348
More information about the llvm-commits
mailing list