[llvm] [InstCombine] Fix InstCombine pass to sink llvm.assume calls (PR #229658)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 02:27:27 PDT 2026


================
@@ -5586,21 +5586,51 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
         return false;
   }
 
+  // Collect assume instructions in SrcBlock whose non-I operands all dominate
+  // DestBlock. SrcBlock dominates DestBlock (unique-predecessor invariant
+  // above), so any instruction defined in SrcBlock or a dominator of SrcBlock
+  // qualifies. We sink these assumes together with I so the alignment/attribute
+  // information they carry is not silently lost.
+  SmallPtrSet<AssumeInst *, 2> AssumesToSink;
+  for (User *U : I->users()) {
+    auto *Assume = dyn_cast<AssumeInst>(U);
+    if (!Assume || Assume->getParent() != SrcBlock)
+      continue;
+    bool CanSink = true;
+    for (Value *Op : Assume->operands()) {
+      auto *OpInst = dyn_cast<Instruction>(Op);
+      if (!OpInst || OpInst == I)
+        continue;
+      if (!DT.dominates(OpInst->getParent(), DestBlock)) {
----------------
anilkund wrote:

You're right that condition is redundant. I have changed it

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


More information about the llvm-commits mailing list