[llvm] [LoopInterchange] Add test for floating point math flags (PR #149090)

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 16 05:55:46 PDT 2025


https://github.com/madhur13490 created https://github.com/llvm/llvm-project/pull/149090

Adding a test where both `ninf` and `reassoc` flags are present on the instruction. We don't know yet if it is legal to interchange. Prima facie, it does not look like it should be legal but more analysis is needed.

>From 12e1bcdc1d30323a4816881d9655969255238c12 Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Wed, 16 Jul 2025 03:01:47 -0700
Subject: [PATCH] [LoopInterchange] Add test for floating math flags

---
 .../reductions-non-wrapped-operations.ll      | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/llvm/test/Transforms/LoopInterchange/reductions-non-wrapped-operations.ll b/llvm/test/Transforms/LoopInterchange/reductions-non-wrapped-operations.ll
index 3ed69485bc8f2..0eb6fe98b8bb7 100644
--- a/llvm/test/Transforms/LoopInterchange/reductions-non-wrapped-operations.ll
+++ b/llvm/test/Transforms/LoopInterchange/reductions-non-wrapped-operations.ll
@@ -411,6 +411,44 @@ exit:
   ret void
 }
 
+; FIXME: Is it really legal to interchange the loops when
+; both reassoc and ninf are set?
+; Check that the interchange is legal if the floating-point addition is marked
+; as reassoc.
+;
+; CHECK:      --- !Pass
+; CHECK-NEXT: Pass:            loop-interchange
+; CHECK-NEXT: Name:            Interchanged
+; CHECK-NEXT: Function:        reduction_reassoc_ninf_fadd
+define void @reduction_reassoc_ninf_fadd(ptr %A) {
+entry:
+  br label %for.i.header
+
+for.i.header:
+  %i = phi i32 [ 0, %entry ], [ %i.inc, %for.i.latch ]
+  %sum.i = phi float [ 0.0, %entry ], [ %sum.i.lcssa, %for.i.latch ]
+  br label %for.j
+
+for.j:
+  %j = phi i32 [ 0, %for.i.header ], [ %j.inc, %for.j ]
+  %sum.j = phi float [ %sum.i, %for.i.header ], [ %sum.j.next, %for.j ]
+  %idx = getelementptr inbounds [2 x [2 x i32]], ptr %A, i32 0, i32 %j, i32 %i
+  %a = load float, ptr %idx, align 4
+  %sum.j.next = fadd reassoc ninf float %sum.j, %a
+  %j.inc = add i32 %j, 1
+  %cmp.j = icmp slt i32 %j.inc, 2
+  br i1 %cmp.j, label %for.j, label %for.i.latch
+
+for.i.latch:
+  %sum.i.lcssa = phi float [ %sum.j.next, %for.j ]
+  %i.inc = add i32 %i, 1
+  %cmp.i = icmp slt i32 %i.inc, 2
+  br i1 %cmp.i, label %for.i.header, label %exit
+
+exit:
+  ret void
+}
+
 ; Check that the loops aren't exchanged if there is a reduction of
 ; non-reassociative floating-point multiplication.
 ;



More information about the llvm-commits mailing list