Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strength reduction misses IV reuse opportunities on 64-bit targets #1469

Closed
sunfishcode opened this issue Jan 8, 2007 · 3 comments
Closed
Labels
bugzilla Issues migrated from bugzilla code-quality loopoptim

Comments

@sunfishcode
Copy link
Member

Bugzilla Link 1097
Resolution FIXED
Resolved on Feb 22, 2010 12:41
Version trunk
OS All

Extended Description

The strength reduction pass is causing the code generator to miss opportunities
for using complex addressing modes.

For this test case:

define void %foo(double* %y) {
entry:
br label %bb

bb:
%i = phi i64 [ 0, %entry ], [ %k, %bb ]
%j = getelementptr double* %y, i64 %i
store double 0.000000e+00, double* %j
%k = add i64 %i, 1
%n = icmp eq i64 %k, 0
br bool %n, label %return, label %bb

return:
ret void
}

The strength reduction pass changes the output on x86-64 to have two induction
variables:

    %iv..inc = add i64 %iv., 1
    ...
    %iv.1.inc = add i64 %iv.1, 8

which causes the codegen to produce this:

.LBB1_1: #bb
movq $0, (%rdi)
addq $8, %rdi
incq %rax
cmpq $0, %rax
jne .LBB1_1 #bb

instead of this:

.LBB1_1: #bb
movq $0, (%rdi,%rax,8)
incq %rax
cmpq $0, %rax
jne .LBB1_1 #bb

Here's a patch that fixes this.

Index: LoopStrengthReduce.cpp

RCS file: /var/cvs/llvm/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp,v
retrieving revision 1.104
diff -u -r1.104 LoopStrengthReduce.cpp
--- LoopStrengthReduce.cpp
+++ LoopStrengthReduce.cpp
@@ -893,7 +893,7 @@
if (unsigned(abs(SInt)) < Scale || (SInt % Scale) != 0)
continue;
std::map<SCEVHandle, IVsOfOneStride>::iterator SI =

  •    IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, Type::Int32Ty));
    
  •    IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy));
     if (SI == IVsByStride.end())
       continue;
     for (std::vector<IVExpr>::iterator II = SI->second.IVs.begin(),
    
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 8, 2007

Nice catch, Dan.

I've applied your patch locally and am just doing a little testing. This should
be committed shortly.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 8, 2007

Patch applied:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070108/042228.html

No apparent regressions on 32-bit (didn't expect any :)

Thanks, Dan!

@lattner
Copy link
Collaborator

lattner commented Jan 8, 2007

Nice catch Dan. Regression test committed here:
Transforms/IndVarsSimplify/2007-01-08-X86-64-Pointer.ll

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
clementval pushed a commit to clementval/llvm-project that referenced this issue Feb 16, 2022
…m#1469)

arguments even in situations where the arguments are required to compute
the LEN value at runtime.

Add tests.

Differential Revision: https://reviews.llvm.org/D119373
clementval pushed a commit to clementval/llvm-project that referenced this issue Feb 16, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla code-quality loopoptim
Projects
None yet
Development

No branches or pull requests

3 participants