Skip to content

Commit a001e97

Browse files
committed
[SimplifyLibCalls] Don't try to manually reprocess calls
The current code for reprocessing the result of fortified libcall simplifications is not correct, because we might simplify to an argument of the original call, and if that is again a libcall, mistakenly think that this is actually the simplification result. Instead of trying to fix this, simply remove the code entirely, because InstCombine nowadays correctly handles reprocessing of SimplifyLibCall results. Fixes #77064.
1 parent 255f95a commit a001e97

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,26 +3735,8 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI, IRBuilderBase &Builder) {
37353735

37363736
// Also try to simplify calls to fortified library functions.
37373737
if (Value *SimplifiedFortifiedCI =
3738-
FortifiedSimplifier.optimizeCall(CI, Builder)) {
3739-
// Try to further simplify the result.
3740-
CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI);
3741-
if (SimplifiedCI && SimplifiedCI->getCalledFunction()) {
3742-
// Ensure that SimplifiedCI's uses are complete, since some calls have
3743-
// their uses analyzed.
3744-
replaceAllUsesWith(CI, SimplifiedCI);
3745-
3746-
// Set insertion point to SimplifiedCI to guarantee we reach all uses
3747-
// we might replace later on.
3748-
IRBuilderBase::InsertPointGuard Guard(Builder);
3749-
Builder.SetInsertPoint(SimplifiedCI);
3750-
if (Value *V = optimizeStringMemoryLibCall(SimplifiedCI, Builder)) {
3751-
// If we were able to further simplify, remove the now redundant call.
3752-
substituteInParent(SimplifiedCI, V);
3753-
return V;
3754-
}
3755-
}
3738+
FortifiedSimplifier.optimizeCall(CI, Builder))
37563739
return SimplifiedFortifiedCI;
3757-
}
37583740

37593741
// Then check for known library functions.
37603742
if (TLI->getLibFunc(*Callee, Func) && isLibFuncEmittable(M, TLI, Func)) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
3+
4+
define void @main(ptr %ptr) {
5+
; CHECK-LABEL: define void @main(
6+
; CHECK-SAME: ptr [[PTR:%.*]]) {
7+
; CHECK-NEXT: [[OPENDIR:%.*]] = call fastcc ptr @opendir(ptr [[PTR]])
8+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(596) [[OPENDIR]], i8 0, i64 596, i1 false)
9+
; CHECK-NEXT: ret void
10+
;
11+
%opendir = call fastcc ptr @opendir(ptr %ptr)
12+
%memset = call ptr @__memset_chk(ptr %opendir, i32 0, i64 596, i64 -1)
13+
ret void
14+
}
15+
16+
declare ptr @__memset_chk(ptr, i32, i64, i64)
17+
18+
declare fastcc ptr @opendir(ptr)

0 commit comments

Comments
 (0)