[llvm] [AggressiveInstCombine] Guard memset with length in [0, 1] (PR #213240)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 00:21:50 PDT 2026
================
@@ -2462,6 +2464,41 @@ 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 one-byte store.
+static bool foldMemSetZeroOrOneLength(Instruction &I, const DataLayout &DL,
+ TargetLibraryInfo &TLI,
+ AssumptionCache &AC, DominatorTree &DT,
+ bool &MadeCFGChange) {
+ auto *MI = dyn_cast<MemSetInst>(&I);
+ if (!MI || isa<ConstantInt>(MI->getLength()))
+ return false;
+
+ SimplifyQuery SQ(DL, &TLI, &DT, &AC, nullptr, /*UseInstrInfo=*/true);
+ KnownBits KnownLen =
+ computeKnownBits(MI->getLength(), SQ.getWithInstruction(MI));
----------------
nikic wrote:
```suggestion
SimplifyQuery SQ(DL, &TLI, &DT, &AC, MI);
KnownBits KnownLen = computeKnownBits(MI->getLength());
```
https://github.com/llvm/llvm-project/pull/213240
More information about the llvm-commits
mailing list