Skip to contentSkip to conversation

selftests/bpf: adjust strobemeta loop to satisfy latest clang

PATCH Applied Andrii Nakryiko 3 participants 3 messages Sep 25, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: adjust strobemeta loop to satisfy latest clang

Some recent changes in latest Clang started causing the following warning when unrolling strobemeta test case main loop:

progs/strobemeta.h:416:2: warning: loop not unrolled: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering [-Wpass-failed=transform-warning]

This patch simplifies loop's exit condition to depend only on constant max iteration number (STROBE_MAX_MAP_ENTRIES), while moving early termination logic inside the loop body. The changes are equivalent from program logic standpoint, but fixes the warning. It also appears to improve generated BPF code, as it fixes previously failing non-unrolled strobemeta test cases.

Cc Alexei Starovoitov <[email protected]>
---
 tools/testing/selftests/bpf/progs/strobemeta.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/strobemeta.h +4 -1
index 8a399bdfd920..067eb625d01c 100644
@@ -413,7 +413,10 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
 #else
 #pragma unroll
 #endif
-	for (int i = 0; i < STROBE_MAX_MAP_ENTRIES && i < map.cnt; ++i) {
+	for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) {
+		if (i >= map.cnt)
+			break;
+
 		descr->key_lens[i] = 0;
 		len = bpf_probe_read_str(payload, STROBE_MAX_STR_LEN,
 					 map.entries[i].key);
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 15 lines · Andrii Nakryiko

Some recent changes in latest Clang started causing the following warning when unrolling strobemeta test case main loop:

progs/strobemeta.h:416:2: warning: loop not unrolled: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering [-Wpass-failed=transform-warning]

This patch simplifies loop's exit condition to depend only on constant max iteration number (STROBE_MAX_MAP_ENTRIES), while moving early termination logic inside the loop body. The changes are equivalent from program logic standpoint, but fixes the warning. It also appears to improve generated BPF code, as it fixes previously failing non-unrolled strobemeta test cases.

Quoted 2 lines
Cc Alexei Starovoitov <[email protected]>

Sounds like a clang regression? Was that from an official release?

Applied.

#2 lore raw
Quoted 17 lines · Daniel Borkmann
Quoted 15 lines · Andrii Nakryiko

Some recent changes in latest Clang started causing the following warning when unrolling strobemeta test case main loop:

progs/strobemeta.h:416:2: warning: loop not unrolled: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering [-Wpass-failed=transform-warning]

This patch simplifies loop's exit condition to depend only on constant max iteration number (STROBE_MAX_MAP_ENTRIES), while moving early termination logic inside the loop body. The changes are equivalent from program logic standpoint, but fixes the warning. It also appears to improve generated BPF code, as it fixes previously failing non-unrolled strobemeta test cases.

Quoted 4 lines
Quoted 2 lines
Cc Alexei Starovoitov <[email protected]>

Sounds like a clang regression? Was that from an official release?

It does, but I didn't dig deep enough to figure out what exactly caused this. The version I used was latest Clang 10 built from sources. Might be worth-while to investigate this further to prevent some other unexpected breakages for user programs.

Quoted 2 lines

Applied.

Thanks!