[llvm] 7f90387 - DSE: fix builtin function recognition to take decl into account
Nuno Lopes via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 02:28:56 PDT 2020
Author: Nuno Lopes
Date: 2020-07-02T10:28:47+01:00
New Revision: 7f903873b8a937acec2e2cc232e70cba53061352
URL: https://github.com/llvm/llvm-project/commit/7f903873b8a937acec2e2cc232e70cba53061352
DIFF: https://github.com/llvm/llvm-project/commit/7f903873b8a937acec2e2cc232e70cba53061352.diff
LOG: DSE: fix builtin function recognition to take decl into account
Added:
Modified:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index f55278d56790..7e172544595a 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -210,18 +210,16 @@ static bool hasAnalyzableMemoryWrite(Instruction *I,
}
}
if (auto *CB = dyn_cast<CallBase>(I)) {
- if (Function *F = CB->getCalledFunction()) {
- LibFunc LF;
- if (TLI.getLibFunc(*F, LF) && TLI.has(LF)) {
- switch (LF) {
- case LibFunc_strcpy:
- case LibFunc_strncpy:
- case LibFunc_strcat:
- case LibFunc_strncat:
- return true;
- default:
- return false;
- }
+ LibFunc LF;
+ if (TLI.getLibFunc(*CB, LF) && TLI.has(LF)) {
+ switch (LF) {
+ case LibFunc_strcpy:
+ case LibFunc_strncpy:
+ case LibFunc_strcat:
+ case LibFunc_strncat:
+ return true;
+ default:
+ return false;
}
}
}
@@ -1581,16 +1579,17 @@ struct DSEState {
return {MemoryLocation::getForDest(MTI)};
if (auto *CB = dyn_cast<CallBase>(I)) {
- if (Function *F = CB->getCalledFunction()) {
- StringRef FnName = F->getName();
- if (TLI.has(LibFunc_strcpy) && FnName == TLI.getName(LibFunc_strcpy))
- return {MemoryLocation(CB->getArgOperand(0))};
- if (TLI.has(LibFunc_strncpy) && FnName == TLI.getName(LibFunc_strncpy))
- return {MemoryLocation(CB->getArgOperand(0))};
- if (TLI.has(LibFunc_strcat) && FnName == TLI.getName(LibFunc_strcat))
- return {MemoryLocation(CB->getArgOperand(0))};
- if (TLI.has(LibFunc_strncat) && FnName == TLI.getName(LibFunc_strncat))
+ LibFunc LF;
+ if (TLI.getLibFunc(*CB, LF) && TLI.has(LF)) {
+ switch (LF) {
+ case LibFunc_strcpy:
+ case LibFunc_strncpy:
+ case LibFunc_strcat:
+ case LibFunc_strncat:
return {MemoryLocation(CB->getArgOperand(0))};
+ default:
+ break;
+ }
}
return None;
}
diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
index e13e3a193d00..94faca15c1b6 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
@@ -1,5 +1,7 @@
; RUN: opt -S -basic-aa -dse -enable-dse-memoryssa < %s | FileCheck %s
+target triple = "x86_64-unknown-linux-gnu"
+
declare i8* @strcpy(i8* %dest, i8* %src) nounwind
define void @test1(i8* %src) {
; CHECK-LABEL: @test1(
@@ -11,13 +13,13 @@ define void @test1(i8* %src) {
ret void
}
-declare i8* @strncpy(i8* %dest, i8* %src, i32 %n) nounwind
+declare i8* @strncpy(i8* %dest, i8* %src, i64 %n) nounwind
define void @test2(i8* %src) {
; CHECK-LABEL: @test2(
%B = alloca [16 x i8]
%dest = getelementptr inbounds [16 x i8], [16 x i8]* %B, i64 0, i64 0
; CHECK-NOT: @strncpy
- %call = call i8* @strncpy(i8* %dest, i8* %src, i32 12)
+ %call = call i8* @strncpy(i8* %dest, i8* %src, i64 12)
; CHECK: ret void
ret void
}
@@ -33,13 +35,13 @@ define void @test3(i8* %src) {
ret void
}
-declare i8* @strncat(i8* %dest, i8* %src, i32 %n) nounwind
+declare i8* @strncat(i8* %dest, i8* %src, i64 %n) nounwind
define void @test4(i8* %src) {
; CHECK-LABEL: @test4(
%B = alloca [16 x i8]
%dest = getelementptr inbounds [16 x i8], [16 x i8]* %B, i64 0, i64 0
; CHECK-NOT: @strncat
- %call = call i8* @strncat(i8* %dest, i8* %src, i32 12)
+ %call = call i8* @strncat(i8* %dest, i8* %src, i64 12)
; CHECK: ret void
ret void
}
More information about the llvm-commits
mailing list