[llvm] [AggressiveInstCombine] Guard memset with length in [0, 1] (PR #213240)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 30 22:20:08 PDT 2026


================
@@ -2462,6 +2464,37 @@ static bool foldMulHigh(Instruction &I) {
   return false;
 }
 
+/// Guard a memset whose nonconstant length is known to be in [0, 1].
+/// Inserts a conditional branch around the memset and specialises the
+/// executed path to a constant length of one.
+static bool foldMemSetZeroOrOneLength(MemSetInst *MI, const DataLayout &DL,
+                                      TargetLibraryInfo &TLI, DominatorTree &DT,
+                                      AssumptionCache &AC,
+                                      bool &MadeCFGChange) {
+  if (isa<ConstantInt>(MI->getLength()))
+    return false;
+
+  SimplifyQuery SQ(DL, &TLI, &DT, &AC, nullptr,
+                   /*UseInstrInfo=*/true, /*CanUseUndef=*/false);
+  KnownBits KnownLen =
+      computeKnownBits(MI->getLength(), SQ.getWithInstruction(MI));
----------------
hsnaveen2u wrote:

Modified

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


More information about the llvm-commits mailing list