[llvm] [InstCombine][NFC] Replace buildAssumeFromKnowledge with CreateAlignmentAssumption (PR #196254)
Nikolas Klauser via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 02:29:43 PDT 2026
================
@@ -3740,15 +3728,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
/// offset and alignment.
/// TODO: we can generate a GEP instead of merging the alignment with
/// the offset.
- RetainedKnowledge RK{Attribute::Alignment,
- MinAlign(Offset, AlignMask + 1), A};
- if (auto *Replacement =
- buildAssumeFromKnowledge(RK, Next, &AC, &DT)) {
-
- Replacement->insertAfter(II->getIterator());
- AC.registerAssumption(Replacement);
- }
- return RemoveConditionFromAssume(II);
+ Builder.CreateAlignmentAssumption(getDataLayout(), A, AlignMask + 1);
----------------
philnik777 wrote:
I'm not sure how to test this. It looks like the `add` and `icmp` get folded first, which means that we never try to compare to zero with an offset smaller than the alignment compare. Any thoughts on what to do?
This is what I tried:
```llvm
define void @align_with_offset(ptr %ptr) {
; CHECK-LABEL: @align_with_offset(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[INT:%.*]] = ptrtoint ptr [[PTR:%.*]] to i64
; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[INT]], 7
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP0]], 5
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
; CHECK-NEXT: ret void
;
entry:
%int = ptrtoint ptr %ptr to i64
%add = add i64 %int, 3
%and = and i64 %add, 7
%cmp = icmp eq i64 0, %and
call void @llvm.assume(i1 %cmp)
ret void
}
```
https://github.com/llvm/llvm-project/pull/196254
More information about the llvm-commits
mailing list