[llvm] [InstCombine] Simplify with.overflow intrinsics with assumption information (PR #84016)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 5 02:21:04 PST 2025
================
@@ -818,6 +818,33 @@ InstCombinerImpl::foldIntrinsicWithOverflowCommon(IntrinsicInst *II) {
if (OptimizeOverflowCheck(WO->getBinaryOp(), WO->isSigned(), WO->getLHS(),
WO->getRHS(), *WO, OperationResult, OverflowResult))
return createOverflowTuple(WO, OperationResult, OverflowResult);
+
+ // See whether we can optimize the overflow check with assumption information.
+ for (User *U : WO->users()) {
+ if (!match(U, m_ExtractValue<1>(m_Value())))
+ continue;
+
+ for (auto &AssumeVH : AC.assumptionsFor(U)) {
+ if (!AssumeVH)
+ continue;
+ CallInst *I = cast<CallInst>(AssumeVH);
+ if (!match(I->getArgOperand(0), m_Not(m_Specific(U))))
+ continue;
+ if (!isValidAssumeForContext(I, II, &DT))
----------------
andjo403 wrote:
is it not a waist to add the DT here as we know that the assume will always be after the WithOverflow Instruction?
also shall the AllowEphemerals be set to true as we try to change the condition for the assume?
```
define i1 @ephemeral_call_assume_no_overflow(i8 noundef %a, i8 noundef %b) {
; CHECK-LABEL: @ephemeral_call_assume_no_overflow(
; CHECK-NEXT: ret i1 true
;
%call = call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 %b)
%overflow = extractvalue { i8, i1 } %call, 1
%not = xor i1 %overflow, true
call void @llvm.assume(i1 %not)
ret i1 %not
}
```
https://github.com/llvm/llvm-project/pull/84016
More information about the llvm-commits
mailing list