[llvm-bugs] [Bug 52104] New: LoopIdiom miscompile
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Oct 7 08:39:22 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=52104
Bug ID: 52104
Summary: LoopIdiom miscompile
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: courbet at google.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
LoopIdiom turns a loop of stores to a zero-size `llvm.memset`:
```
%struct.S = type { [4 x i32], i32 }
define void @f(%struct.S* nocapture nonnull align 4 dereferenceable(20) %0)
local_unnamed_addr #0 align 32 {
%2 = getelementptr inbounds %struct.S, %struct.S* %0, i64 0, i32 1
%3 = load i32, i32* %2, align 4
br label %4
4: ; preds = %4, %1
%5 = phi i32 [ %9, %4 ], [ %3, %1 ]
%6 = and i32 %5, 3
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds %struct.S, %struct.S* %0, i64 0, i32 0, i64 %7
store i32 0, i32* %8, align 4
%9 = add nsw i32 %5, 1
%10 = and i32 %9, 3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = phi i32 [ %9, %4 ]
store i32 %13, i32* %2, align 4
ret void
}
```
->
```
define void @f(%struct.S* nocapture nonnull align 4 dereferenceable(20) %0)
local_unnamed_addr align 32 {
%2 = getelementptr inbounds %struct.S, %struct.S* %0, i64 0, i32 1
%3 = load i32, i32* %2, align 4
%4 = trunc i32 %3 to i2
%5 = zext i2 %4 to i64
%scevgep = getelementptr %struct.S, %struct.S* %0, i64 0, i32 0, i64 %5
%scevgep1 = bitcast i32* %scevgep to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %scevgep1, i8 0, i64 0, i1 false)
br label %6
6: ; preds = %6, %1
%7 = phi i32 [ %11, %6 ], [ %3, %1 ]
%8 = and i32 %7, 3
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds %struct.S, %struct.S* %0, i64 0, i32 0, i64 %9
%11 = add nsw i32 %7, 1
%12 = and i32 %11, 3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = phi i32 [ %11, %6 ]
store i32 %15, i32* %2, align 4
ret void
}
```
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211007/6a1efd12/attachment.html>
More information about the llvm-bugs
mailing list