Skip to content

Conversation

@wzssyqa
Copy link
Contributor

@wzssyqa wzssyqa commented Mar 28, 2025

Setting EnableLoopTermFold enables loop-term-fold pass.

@llvmbot
Copy link
Member

llvmbot commented Mar 28, 2025

@llvm/pr-subscribers-llvm-transforms

Author: YunQiang Su (wzssyqa)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/133378.diff

2 Files Affected:

  • (modified) llvm/lib/Target/Mips/MipsTargetMachine.cpp (+1)
  • (modified) llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll (+56-29)
diff --git a/llvm/lib/Target/Mips/MipsTargetMachine.cpp b/llvm/lib/Target/Mips/MipsTargetMachine.cpp index 30eb739212113..4d1bcb17e2fb5 100644 --- a/llvm/lib/Target/Mips/MipsTargetMachine.cpp +++ b/llvm/lib/Target/Mips/MipsTargetMachine.cpp @@ -233,6 +233,7 @@ class MipsPassConfig : public TargetPassConfig { // can break this requirement, so disable it when long branch pass is // enabled. EnableTailMerge = !getMipsSubtarget().enableLongBranchPass(); + EnableLoopTermFold = true; } MipsTargetMachine &getMipsTargetMachine() const { diff --git a/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll b/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll index 9f562451bd40a..2a40797540cb1 100644 --- a/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll +++ b/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll @@ -1,5 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 -; RUN: opt < %s -passes=loop-reduce -S | FileCheck %s +; RUN: opt < %s -passes=loop-reduce,loop-term-fold -S | FileCheck %s --check-prefix=CHECK-OPT +; RUN: llc < %s -o - | FileCheck %s --check-prefix=CHECK-LLC target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" target triple = "mips-unknown-linux-gnu" @@ -8,20 +9,34 @@ target triple = "mips-unknown-linux-gnu" ; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) define dso_local void @in128000(i32 noundef signext %k, i32 noundef signext %n) local_unnamed_addr #0 { -; CHECK-LABEL: define dso_local void @in128000( -; CHECK-SAME: i32 noundef signext [[K:%.*]], i32 noundef signext [[N:%.*]]) local_unnamed_addr { -; CHECK-NEXT: [[ENTRY:.*]]: -; CHECK-NEXT: br label %[[FOR_BODY:.*]] -; CHECK: [[FOR_COND_CLEANUP:.*]]: -; CHECK-NEXT: ret void -; CHECK: [[FOR_BODY]]: -; CHECK-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], %[[FOR_BODY]] ], [ @x, %[[ENTRY]] ] -; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], %[[FOR_BODY]] ], [ 128000, %[[ENTRY]] ] -; CHECK-NEXT: store i32 [[K]], ptr [[LSR_IV1]], align 4 -; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i32 [[LSR_IV]], -1 -; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i32 4 -; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[LSR_IV_NEXT]], 0 -; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[FOR_COND_CLEANUP]], label %[[FOR_BODY]] +; CHECK-LLC-LABEL: in128000: +; CHECK-LLC: # %bb.0: # %entry +; CHECK-LLC-NEXT: lui $1, %hi(x) +; CHECK-LLC-NEXT: addiu $2, $1, %lo(x) +; CHECK-LLC-NEXT: lui $1, 7 +; CHECK-LLC-NEXT: ori $1, $1, 53248 +; CHECK-LLC-NEXT: addu $3, $2, $1 +; CHECK-LLC-NEXT: $BB0_1: # %for.body +; CHECK-LLC-NEXT: # =>This Inner Loop Header: Depth=1 +; CHECK-LLC-NEXT: sw $4, 0($2) +; CHECK-LLC-NEXT: addiu $2, $2, 4 +; CHECK-LLC-NEXT: bne $2, $3, $BB0_1 +; CHECK-LLC-NEXT: nop +; CHECK-LLC-NEXT: # %bb.2: # %for.cond.cleanup +; CHECK-LLC-NEXT: jr $ra +; CHECK-LLC-NEXT: nop +; CHECK-OPT-LABEL: define dso_local void @in128000( +; CHECK-OPT-SAME: i32 noundef signext [[K:%.*]], i32 noundef signext [[N:%.*]]) local_unnamed_addr { +; CHECK-OPT-NEXT: [[ENTRY:.*]]: +; CHECK-OPT-NEXT: br label %[[FOR_BODY:.*]] +; CHECK-OPT: [[FOR_COND_CLEANUP:.*]]: +; CHECK-OPT-NEXT: ret void +; CHECK-OPT: [[FOR_BODY]]: +; CHECK-OPT-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], %[[FOR_BODY]] ], [ @x, %[[ENTRY]] ] +; CHECK-OPT-NEXT: store i32 [[K]], ptr [[LSR_IV1]], align 4 +; CHECK-OPT-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i32 4 +; CHECK-OPT-NEXT: [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND:%.*]] = icmp eq ptr [[SCEVGEP]], getelementptr inbounds nuw (i8, ptr @x, i32 512000) +; CHECK-OPT-NEXT: br i1 [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND]], label %[[FOR_COND_CLEANUP]], label %[[FOR_BODY]] ; entry: br label %for.body @@ -40,20 +55,32 @@ for.body: ; preds = %entry, %for.body ; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) define dso_local void @in1000(i32 noundef signext %k, i32 noundef signext %n) local_unnamed_addr #0 { -; CHECK-LABEL: define dso_local void @in1000( -; CHECK-SAME: i32 noundef signext [[K:%.*]], i32 noundef signext [[N:%.*]]) local_unnamed_addr { -; CHECK-NEXT: [[ENTRY:.*]]: -; CHECK-NEXT: br label %[[FOR_BODY:.*]] -; CHECK: [[FOR_COND_CLEANUP:.*]]: -; CHECK-NEXT: ret void -; CHECK: [[FOR_BODY]]: -; CHECK-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], %[[FOR_BODY]] ], [ @x, %[[ENTRY]] ] -; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], %[[FOR_BODY]] ], [ 1000, %[[ENTRY]] ] -; CHECK-NEXT: store i32 [[K]], ptr [[LSR_IV1]], align 4 -; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i32 [[LSR_IV]], -1 -; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i32 4 -; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[LSR_IV_NEXT]], 0 -; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[FOR_COND_CLEANUP]], label %[[FOR_BODY]] +; CHECK-LLC-LABEL: in1000: +; CHECK-LLC: # %bb.0: # %entry +; CHECK-LLC-NEXT: lui $1, %hi(x) +; CHECK-LLC-NEXT: addiu $2, $1, %lo(x) +; CHECK-LLC-NEXT: addiu $3, $2, 4000 +; CHECK-LLC-NEXT: $BB1_1: # %for.body +; CHECK-LLC-NEXT: # =>This Inner Loop Header: Depth=1 +; CHECK-LLC-NEXT: sw $4, 0($2) +; CHECK-LLC-NEXT: addiu $2, $2, 4 +; CHECK-LLC-NEXT: bne $2, $3, $BB1_1 +; CHECK-LLC-NEXT: nop +; CHECK-LLC-NEXT: # %bb.2: # %for.cond.cleanup +; CHECK-LLC-NEXT: jr $ra +; CHECK-LLC-NEXT: nop +; CHECK-OPT-LABEL: define dso_local void @in1000( +; CHECK-OPT-SAME: i32 noundef signext [[K:%.*]], i32 noundef signext [[N:%.*]]) local_unnamed_addr { +; CHECK-OPT-NEXT: [[ENTRY:.*]]: +; CHECK-OPT-NEXT: br label %[[FOR_BODY:.*]] +; CHECK-OPT: [[FOR_COND_CLEANUP:.*]]: +; CHECK-OPT-NEXT: ret void +; CHECK-OPT: [[FOR_BODY]]: +; CHECK-OPT-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], %[[FOR_BODY]] ], [ @x, %[[ENTRY]] ] +; CHECK-OPT-NEXT: store i32 [[K]], ptr [[LSR_IV1]], align 4 +; CHECK-OPT-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i32 4 +; CHECK-OPT-NEXT: [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND:%.*]] = icmp eq ptr [[SCEVGEP]], getelementptr inbounds nuw (i8, ptr @x, i32 4000) +; CHECK-OPT-NEXT: br i1 [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND]], label %[[FOR_COND_CLEANUP]], label %[[FOR_BODY]] ; entry: br label %for.body 
@wzssyqa wzssyqa merged commit 71f43a7 into llvm:main Mar 28, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 28, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/21445

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure) ******************** TEST 'LLVM :: Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll' FAILED ******************** Exit Code: 2 Command Output (stderr): -- /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll -passes=loop-reduce,loop-term-fold -S | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-OPT # RUN: at line 2 + /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -passes=loop-reduce,loop-term-fold -S + /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-OPT /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt: WARNING: failed to create target machine for 'mips-unknown-linux-gnu': unable to get target for 'mips-unknown-linux-gnu', see --version and --triple. /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll -o - | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC # RUN: at line 3 + /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -o - + /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc: error: unable to get target for 'mips-unknown-linux-gnu', see --version and --triple. FileCheck error: '<stdin>' is empty. FileCheck command line: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC -- ******************** 
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 28, 2025

LLVM Buildbot has detected a new failure on builder llvm-nvptx-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/15490

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure) ******************** TEST 'LLVM :: Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll' FAILED ******************** Exit Code: 2 Command Output (stderr): -- /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/opt < /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll -passes=loop-reduce,loop-term-fold -S | /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-OPT # RUN: at line 2 + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/opt -passes=loop-reduce,loop-term-fold -S + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-OPT /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'mips-unknown-linux-gnu': unable to get target for 'mips-unknown-linux-gnu', see --version and --triple. /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/llc < /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll -o - | /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC # RUN: at line 3 + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/llc -o - + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/llc: error: unable to get target for 'mips-unknown-linux-gnu', see --version and --triple. FileCheck error: '<stdin>' is empty. FileCheck command line: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC -- ******************** 
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 28, 2025

LLVM Buildbot has detected a new failure on builder llvm-nvptx64-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/15493

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure) ******************** TEST 'LLVM :: Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll' FAILED ******************** Exit Code: 2 Command Output (stderr): -- /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/opt < /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll -passes=loop-reduce,loop-term-fold -S | /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-OPT # RUN: at line 2 + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/opt -passes=loop-reduce,loop-term-fold -S + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-OPT /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/opt: WARNING: failed to create target machine for 'mips-unknown-linux-gnu': unable to get target for 'mips-unknown-linux-gnu', see --version and --triple. /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/llc < /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll -o - | /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC # RUN: at line 3 + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/llc -o - + /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/llc: error: unable to get target for 'mips-unknown-linux-gnu', see --version and --triple. FileCheck error: '<stdin>' is empty. FileCheck command line: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/LoopStrengthReduce/Mips/long-array-initialize.ll --check-prefix=CHECK-LLC -- ******************** 
@TomWeaver18
Copy link
Contributor

@wzssyqa Hello and good morning from the UK,

Are there any plans to address the failure introduced in long-array-initialize.ll caused by the changes added herein?

We have several build bots and configurations that have gone red:

https://lab.llvm.org/buildbot/#/builders/190/builds/17267
https://lab.llvm.org/buildbot/#/builders/144/builds/21445
https://lab.llvm.org/buildbot/#/builders/46/builds/14343

The change has already been in for over an hour, if a fix isn't easy or forthcoming, please consider reverting the change until one can be devised 👍

Thanks in advance,
Tom W

TomWeaver18 pushed a commit that referenced this pull request Mar 28, 2025
@TomWeaver18
Copy link
Contributor

My apologies but I've had to revert this change for now due to the ongoing build bot failures:

af15027

@wzssyqa
Copy link
Contributor Author

wzssyqa commented Mar 28, 2025

Ohh. I forgot to add lit.local.cfg. I will add one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants