Index: llvm/lib/Transforms/Utils/Local.cpp =================================================================== --- llvm/lib/Transforms/Utils/Local.cpp +++ llvm/lib/Transforms/Utils/Local.cpp @@ -430,6 +430,10 @@ return true; } + if (CallInst *CI = isFreeCall(I, TLI)) + if (Constant *C = dyn_cast(CI->getArgOperand(0))) + return C->isNullValue() || isa(C); + if (!I->willReturn()) return false; @@ -483,10 +487,6 @@ if (isAllocLikeFn(I, TLI)) return true; - if (CallInst *CI = isFreeCall(I, TLI)) - if (Constant *C = dyn_cast(CI->getArgOperand(0))) - return C->isNullValue() || isa(C); - if (auto *Call = dyn_cast(I)) if (isMathLibCallNoop(Call, TLI)) return true; Index: llvm/test/Transforms/InstCombine/free-undef.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/InstCombine/free-undef.ll @@ -0,0 +1,35 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instcombine -S -o - | FileCheck %s -check-prefix=INSTCOMBINE +; RUN: opt < %s -instcombine -simplifycfg -S -o - | FileCheck %s -check-prefix=SIMPLIFYCFG + +; Function Attrs: mustprogress nounwind uwtable +define dso_local i32 @_Z4funcv() local_unnamed_addr { +; CHECK-LABEL: @_Z4funcv( +; +; INSTCOMBINE-LABEL: @_Z4funcv( +; INSTCOMBINE-NOT: store +; +; SIMPLIFYCFG-LABEL: @_Z4funcv( +; SIMPLIFYCFG-NOT: unreachable +; +entry: + br label %delete.notnull + +delete.notnull: ; preds = %entry + call void @_ZdlPv(i8* undef) + br label %delete.end + +delete.end: ; preds = %delete.notnull + ret i32 1 +} + +; Function Attrs: nobuiltin nounwind +declare dso_local void @_ZdlPv(i8*) local_unnamed_addr + +; Function Attrs: mustprogress norecurse nounwind uwtable +define dso_local i32 @main() local_unnamed_addr { +entry: + %call = call i32 @_Z4funcv() + ret i32 0 +} +