diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -2012,7 +2012,9 @@ return Size; } - bool hasIslandsInfo() const { return !!Islands; } + bool hasIslandsInfo() const { + return Islands && (hasConstantIsland() || !Islands->Dependency.empty()); + } bool hasConstantIsland() const { return Islands && !Islands->DataOffsets.empty(); diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -4426,7 +4426,7 @@ } bool BinaryFunction::isAArch64Veneer() const { - if (empty()) + if (empty() || hasIslandsInfo()) return false; BinaryBasicBlock &BB = **BasicBlocks.begin(); diff --git a/bolt/lib/Passes/IdenticalCodeFolding.cpp b/bolt/lib/Passes/IdenticalCodeFolding.cpp --- a/bolt/lib/Passes/IdenticalCodeFolding.cpp +++ b/bolt/lib/Passes/IdenticalCodeFolding.cpp @@ -162,6 +162,9 @@ if (A.isMultiEntry() || B.isMultiEntry()) return false; + if (A.hasIslandsInfo() || B.hasIslandsInfo()) + return false; + // Process both functions in either DFS or existing order. const BinaryFunction::BasicBlockOrderType OrderA = opts::UseDFS diff --git a/bolt/test/AArch64/prevent-ci-folding.s b/bolt/test/AArch64/prevent-ci-folding.s new file mode 100644 --- /dev/null +++ b/bolt/test/AArch64/prevent-ci-folding.s @@ -0,0 +1,34 @@ +// This test checks that functions containing Constant Islands are not folded even +// if they have the same data + +// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o +// RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q +// RUN: llvm-bolt -icf -lite=false %t.exe -o %t.bolt +// RUN: llvm-objdump -d -j .text %t.bolt | FileCheck %s + +// CHECK: : +// CHECK: : + +func1: + add x0, x0, #1 + ret + .word 0xdeadbeef + .word 0xdeadbeef +.size func1, .-func1 + +func2: + add x0, x0, #1 + ret + .word 0xdeadbeef + .word 0xdeadbeef +.size func2, .-func2 + +.global main +.type main, %function +main: + mov x0, #0 + bl func1 + bl func2 + sub x0, x0, #2 + mov w8, #93 + svc #0