[llvm] [GVN] Support rnflow pattern matching and transform (PR #162259)
Madhur Amilkanthwar via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 03:03:29 PDT 2026
madhur13490 wrote:
> Miscompilation reproducer: https://alive2.llvm.org/ce/z/eKnV29.
>
> ```llvm
> ; ./bin/opt -S -gvn-enable-min-finding-select-pattern -passes=gvn test.ll
> define i32 @test() {
> entry:
> %base = getelementptr [4 x float], ptr @arr, i64 0, i64 0
> br label %loop
>
> loop:
> %iv = phi i64 [ 3, %entry ], [ %iv.next, %loop ]
> %ctr = phi i64 [ 3, %entry ], [ %ctr.next, %loop ]
> %min.idx = phi i32 [ 1, %entry ], [ %min.idx.next, %loop ]
> %iv.next = add nsw i64 %iv, -1
> %ptr.iv = getelementptr float, ptr %base, i64 %iv
> %val.first = load float, ptr %ptr.iv, align 4
> %min.idx.ext = sext i32 %min.idx to i64
> %gep.typed = getelementptr float, ptr %base, i64 %min.idx.ext
> %gep.offset = getelementptr i8, ptr %gep.typed, i64 -4
> %val.min = load float, ptr %gep.offset, align 4
> %cmp = fcmp olt float %val.first, %val.min
> %new.idx = trunc nsw i64 %iv.next to i32
> %min.idx.next = select i1 %cmp, i32 %new.idx, i32 %min.idx
> %ctr.next = add nsw i64 %ctr, -1
> %cond = icmp samesign ugt i64 %ctr, 1
> br i1 %cond, label %loop, label %exit
>
> exit:
> ret i32 %min.idx.next
> }
> ```
Thanks @antoniofrighetto. Yes, I confirm this was not intentional and recognizer shouldn't have pass through. I have added checks to strengthen around GEP structure. Further, the recognizer is now split into 5 phases for ease of reading and the big test file is now split across positives and negatives. Please have a look.
https://github.com/llvm/llvm-project/pull/162259
More information about the llvm-commits
mailing list