[llvm] [InstCombine] Remove redundant alignment assumptions. (PR #123348)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 13:40:55 PST 2025


================
@@ -3218,6 +3219,28 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
         MaybeSimplifyHint(OBU.Inputs[0]);
         MaybeSimplifyHint(OBU.Inputs[1]);
       }
+
+      // Try to remove redundant alignment assumptions.
+      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;
+
+        // Try to get the instruction before the assumption to use as context.
+        Instruction *CtxI = nullptr;
+        if (CtxI && II->getParent()->begin() != II->getIterator())
+          CtxI = II->getPrevNode();
----------------
nikic wrote:

Hm, I don't get how this works. Don't we scan forward across guaranteed-to-transfer instructions and should find the assume that way? Esp. as we disable the ephemeral value handling for these assumptions.

https://github.com/llvm/llvm-project/pull/123348


More information about the llvm-commits mailing list