[InstCombine] Move noundef assume bundles on loads into metadata (#203395)

This commit is contained in:
Nikolas Klauser 2026-06-12 05:17:46 +02:00 committed by GitHub
parent 69371e6c31
commit 0591eef767
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View file

@ -3744,6 +3744,15 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
if (isGuaranteedNotToBeUndefOrPoison(Val, &AC, II, &DT))
return RemoveBundle();
if (auto *LI = dyn_cast<LoadInst>(Val);
LI &&
isValidAssumeForContext(II, LI, &DT, /*AllowEphemerals=*/true)) {
LI->setMetadata(LLVMContext::MD_noundef,
MDNode::get(II->getContext(), {}));
return RemoveBundle();
}
} break;
case BundleAttr::SeparateStorage: {

View file

@ -1300,7 +1300,31 @@ define void @redundant_assume_noundef(i32 noundef %val) {
ret void
}
define i32 @assume_noundef_on_load(ptr %ptr) {
; CHECK-LABEL: @assume_noundef_on_load(
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[PTR:%.*]], align 4, !noundef [[META6]]
; CHECK-NEXT: ret i32 [[VAL]]
;
%val = load i32, ptr %ptr
call void @llvm.assume(i1 true) [ "noundef"(i32 %val) ]
ret i32 %val
}
define i32 @assume_noundef_on_load_after_call(ptr %ptr) {
; CHECK-LABEL: @assume_noundef_on_load_after_call(
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[PTR:%.*]], align 4
; CHECK-NEXT: call void @block()
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "noundef"(i32 [[VAL]]) ]
; CHECK-NEXT: ret i32 [[VAL]]
;
%val = load i32, ptr %ptr
call void @block()
call void @llvm.assume(i1 true) [ "noundef"(i32 %val) ]
ret i32 %val
}
declare void @use(i1)
declare void @block()
declare void @llvm.dbg.value(metadata, metadata, metadata)
!llvm.dbg.cu = !{!0}