[llvm] [X86][SimplifyCFG] Support hoisting load/store with conditional faulting (PR #96878)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 4 11:25:19 PDT 2024
dtcxzyw wrote:
@KanRobert Can you file a separate PR to support conditional load/store of ptrs with +cf? Then I can share another miscompilation reproducer :)
```
@e = dso_local global ptr null, align 8
@f = dso_local global ptr @e, align 8
@g = dso_local global ptr @f, align 8
@h = dso_local global ptr @g, align 8
@d = dso_local global i8 0, align 1
@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@c = dso_local global i64 0, align 8
; Function Attrs: nounwind uwtable
define dso_local void @i() #0 {
entry:
%p = alloca i32, align 4
call void @llvm.lifetime.start.p0(i64 4, ptr %p) #3
store i8 0, ptr @d, align 1
br label %for.cond
for.cond: ; preds = %for.inc, %entry
%0 = load i8, ptr @d, align 1
%conv = sext i8 %0 to i32
%cmp = icmp slt i32 %conv, 2
br i1 %cmp, label %for.body, label %for.end
for.body: ; preds = %for.cond
%1 = load ptr, ptr @h, align 8
%2 = load ptr, ptr %1, align 8
%3 = load ptr, ptr %2, align 8
%4 = load ptr, ptr %3, align 8
%5 = load ptr, ptr @f, align 8
store ptr %4, ptr %5, align 8
%6 = load ptr, ptr @h, align 8
%7 = load ptr, ptr %6, align 8
%8 = load ptr, ptr %7, align 8
store ptr %4, ptr %8, align 8
br label %for.inc
for.inc: ; preds = %for.body
%9 = load i8, ptr @d, align 1
%inc = add i8 %9, 1
store i8 %inc, ptr @d, align 1
br label %for.cond
for.end: ; preds = %for.cond
store i32 0, ptr %p, align 4
br label %for.cond2
for.cond2: ; preds = %for.body3, %for.end
%10 = load i32, ptr %p, align 4
%tobool = icmp ne i32 %10, 0
br i1 %tobool, label %for.body3, label %for.end4
for.body3: ; preds = %for.cond2
br label %for.cond2
for.end4: ; preds = %for.cond2
call void @llvm.lifetime.end.p0(i64 4, ptr %p)
ret void
}
; Function Attrs: nounwind uwtable
define dso_local signext i32 @main() #0 {
entry:
%retval = alloca i32, align 4
store i32 0, ptr %retval, align 4
call void @i()
%0 = load i64, ptr @c, align 8
%conv = trunc i64 %0 to i32
%call = call signext i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef signext %conv)
ret i32 0
}
declare noundef signext i32 @printf(ptr nocapture noundef readonly, ...)
```
https://github.com/llvm/llvm-project/pull/96878
More information about the llvm-commits
mailing list