Skip to content

Commit 1648232

Browse files
committed
!fixup check alignment is ConstantInt.
1 parent a92e56c commit 1648232

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,8 +3104,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
31043104
if (!LI ||
31053105
!isValidAssumeForContext(II, LI, &DT, /*AllowEphemerals=*/true))
31063106
continue;
3107-
auto *Align = cast<ConstantInt>(OBU.Inputs[1]);
3108-
if (!isPowerOf2_64(Align->getZExtValue()))
3107+
auto *Align = dyn_cast<ConstantInt>(OBU.Inputs[1]);
3108+
if (!Align || !isPowerOf2_64(Align->getZExtValue()))
31093109
continue;
31103110
LI->setMetadata(
31113111
LLVMContext::MD_align,

llvm/test/Transforms/InstCombine/assume-align.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ define ptr @dont_fold_assume_align_zero_of_loaded_pointer_into_align_metadata(pt
169169
call void @llvm.assume(i1 true) [ "align"(ptr %p2, i64 0) ]
170170
ret ptr %p2
171171
}
172+
173+
; !align must have a constant integer alignment.
174+
define ptr @dont_fold_assume_align_not_constant_of_loaded_pointer_into_align_metadata(ptr %p, i64 %align) {
175+
; CHECK-LABEL: @dont_fold_assume_align_not_constant_of_loaded_pointer_into_align_metadata(
176+
; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P:%.*]], align 8
177+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[P2]], i64 [[ALIGN:%.*]]) ]
178+
; CHECK-NEXT: ret ptr [[P2]]
179+
;
180+
%p2 = load ptr, ptr %p
181+
call void @llvm.assume(i1 true) [ "align"(ptr %p2, i64 %align) ]
182+
ret ptr %p2
183+
}
184+
172185
;.
173186
; CHECK: [[META0]] = !{i64 8}
174187
;.

0 commit comments

Comments
 (0)