[llvm] [LoopInterchange] Avoid overflow in the memory-instruction ratio check (PR #214920)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 12:23:31 PDT 2026


================
@@ -1,8 +1,15 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
 ; RUN: opt < %s -passes=loop-interchange -S -loop-interchange-profitabilities=ignore \
-; RUN:          -loop-interchange-max-mem-instr-ratio=1 | FileCheck %s --check-prefixes=CHECK,CHECK-RATIO-1
+; RUN:          -loop-interchange-max-mem-instr-ratio=1 | FileCheck %s --check-prefixes=CHECK-RATIO-1
 ; RUN: opt < %s -passes=loop-interchange -S -loop-interchange-profitabilities=ignore \
-; RUN:          -loop-interchange-max-mem-instr-ratio=100 | FileCheck %s --check-prefixes=CHECK,CHECK-RATIO-100
+; RUN:          -loop-interchange-max-mem-instr-ratio=100 | FileCheck %s --check-prefixes=CHECK-RATIO-100
+; The loop nest has 20 instructions and 10 stores. With 32-bit arithmetic,
+; 2147483648 * 20 wraps to zero, so the ratio guard rejects this otherwise
+; eligible nest. The guard bounds analysis cost, not legality. If the body
+; changes, keep the instruction count even, or choose a ratio whose 32-bit
+; product with the instruction count wraps below the squared load/store count.
+; RUN: opt < %s -passes=loop-interchange -S -loop-interchange-profitabilities=ignore \
+; RUN:          -loop-interchange-max-mem-instr-ratio=2147483648 | FileCheck %s --check-prefixes=CHECK-RATIO-100
----------------
MattPD wrote:

Done.


https://github.com/llvm/llvm-project/pull/214920


More information about the llvm-commits mailing list