Open Quuxplusone opened 6 years ago
Bugzilla Link | PR38815 |
Status | NEW |
Importance | P normal |
Reported by | Jeremy Morse (jeremy.morse.llvm@gmail.com) |
Reported on | 2018-09-03 09:49:07 -0700 |
Last modified on | 2021-08-05 11:36:20 -0700 |
Version | trunk |
Hardware | PC Linux |
CC | chackz0x12@gmail.com, chris.jackson@sony.com, greg.bedwell@sony.com, international.phantom@gmail.com, llvm-bugs@lists.llvm.org, markus.lavin@ericsson.com, paul_robinson@playstation.sony.com |
Fixed by commit(s) | |
Attachments | |
Blocks | PR38768 |
Blocked by | |
See also |
For a better understanding:
-------->8--------
int foo(int blah) {
int bob;
for (bob = blah; bob < blah + 10; ++bob) {
if (bob < 3)
return 0;
}
return 1;
}
-------->8--------
*** IR Dump Before Loop Strength Reduction ***
==============================================
; Preheader:
entry:
[..]
%cmp1 = icmp slt i32 %blah, 3, !dbg !16
%0 = add nsw i32 %blah, 9, !dbg !21
br label %for.body, !dbg !22
; Loop:
for.body:
%bob.06 = phi i32 [ %blah, %entry ], [ %inc, %for.cond ]
call void @llvm.dbg.value(metadata i32 %bob.06, metadata !14, ...), !dbg !15
call void @llvm.dbg.value(metadata i32 %bob.06, metadata !14, ...), !dbg !15
br i1 %cmp1, label %cleanup, label %for.cond, !dbg !26
for.cond:
%inc = add nsw i32 %bob.06, 1, !dbg !23
call void @llvm.dbg.value(metadata i32 %inc, metadata !14, ...), !dbg !15
call void @llvm.dbg.value(metadata i32 %inc, metadata !14, ...), !dbg !15
%cmp = icmp slt i32 %bob.06, %0, !dbg !23
br i1 %cmp, label %for.body, label %cleanup, !dbg !22, !llvm.loop !24
; Exit blocks
cleanup:
[..]
*** IR Dump After Loop Strength Reduction ***
==============================================
; Preheader:
entry:
[..]
%cmp1 = icmp slt i32 %blah, 3, !dbg !16
%0 = add nsw i32 %blah, 9, !dbg !21
%1 = add i32 %blah, -1, !dbg !22
br label %for.body, !dbg !22
; Loop:
for.body:
%lsr.iv = phi i32 [ %lsr.iv.next, %for.cond ], [ %1, %entry ]
call void @llvm.dbg.value(metadata i32 undef, metadata !14, ...), !dbg !15
call void @llvm.dbg.value(metadata i32 undef, metadata !14, ...), !dbg !15
br i1 %cmp1, label %cleanup, label %for.cond, !dbg !26
for.cond:
call void @llvm.dbg.value(metadata i32 undef, metadata !14, ...), !dbg !15
call void @llvm.dbg.value(metadata i32 undef, metadata !14, ...), !dbg !15
%lsr.iv.next = add i32 %lsr.iv, 1, !dbg !23
%cmp = icmp slt i32 %lsr.iv.next, %0, !dbg !23
br i1 %cmp, label %for.body, label %cleanup, !dbg !22, !llvm.loop !24
; Exit blocks
cleanup:
[..]
'bob' and 'blah' have been optimized out.
'bob' replaced by: '%lsr.iv' and '%lsr.iv.next'
'blah' replaced by: '%1'
NB, Alexey made a start on this here: https://reviews.llvm.org/D67770
This issue is being addressed in https://reviews.llvm.org/D87494
This particular issue is resolved in commit 06758c6a6135f59deec8e73d4fcb69946ab47f54
Please see https://reviews.llvm.org/D105207 for some more recent work in this area.