[llvm] [InstCombine] Don't consider aligned_alloc removable if icmp uses result (PR #69474)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 03:09:32 PDT 2023
================
@@ -2430,6 +2430,26 @@ static bool isAllocSiteRemovable(Instruction *AI,
unsigned OtherIndex = (ICI->getOperand(0) == PI) ? 1 : 0;
if (!isNeverEqualToUnescapedAlloc(ICI->getOperand(OtherIndex), TLI, AI))
return false;
+
+ // Do not fold compares to aligned_alloc calls, as they may have to
+ // return null in case the required alignment cannot be satisfied,
+ // unless we can prove that both alignment and size are valid.
+ auto AlignmentAndSizeKnownValid = [](CallBase *CB) {
+ // Check if alignment and size of a call to aligned_alloc is valid,
+ // that is alignment is a power-of-2 and the size is a multiple of the
+ // alignment.
+ const APInt *Alignment;
+ const APInt *Size;
+ return match(CB->getArgOperand(0), m_APInt(Alignment)) &&
+ match(CB->getArgOperand(1), m_APInt(Size)) &&
+ Alignment->isPowerOf2() && Size->urem(*Alignment).isZero();
+ };
+ auto *CB = dyn_cast<CallBase>(AI);
----------------
fhahn wrote:
No, it's the same. Personally I prefer passing args explicitly in cases such as this one, as it makes things at the call site more explicit.
https://github.com/llvm/llvm-project/pull/69474
More information about the llvm-commits
mailing list