-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[InstSimplify] Correctly handle comparison with zero-size allocs #115728
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,8 +234,9 @@ define i1 @zst_alloca_start() { | |
; CHECK-LABEL: @zst_alloca_start( | ||
; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8 | ||
; CHECK-NEXT: [[A2:%.*]] = alloca {}, align 1 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[A]], [[A2]] | ||
; CHECK-NEXT: call void @escape(ptr [[A]], ptr [[A2]]) | ||
; CHECK-NEXT: ret i1 false | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%a = alloca i64 | ||
%a2 = alloca {}, align 1 | ||
|
@@ -249,8 +250,10 @@ define i1 @zst_alloca_middle() { | |
; CHECK-LABEL: @zst_alloca_middle( | ||
; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8 | ||
; CHECK-NEXT: [[A2:%.*]] = alloca {}, align 1 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 4 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP]], [[A2]] | ||
; CHECK-NEXT: call void @escape(ptr [[A]], ptr [[A2]]) | ||
; CHECK-NEXT: ret i1 false | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%a = alloca i64 | ||
%a2 = alloca {}, align 1 | ||
|
@@ -282,8 +285,9 @@ define i1 @zst_alloca_end() { | |
define i1 @zst_global_start() { | ||
; CHECK-LABEL: @zst_global_start( | ||
; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[A]], @gz | ||
; CHECK-NEXT: call void @escape(ptr [[A]], ptr @gz) | ||
; CHECK-NEXT: ret i1 false | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case (alloca != global) should be folded. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently LLVM doesn't make assumptions about how different allocations types are positioned relative to each other. We'd have to add LangRef wording for this, to require that allocas and globals allocations cannot be adjacent. |
||
; | ||
%a = alloca i64 | ||
%gep = getelementptr i8, ptr %a, i64 0 | ||
|
@@ -295,8 +299,10 @@ define i1 @zst_global_start() { | |
define i1 @zst_global_middle() { | ||
; CHECK-LABEL: @zst_global_middle( | ||
; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 4 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP]], @gz | ||
; CHECK-NEXT: call void @escape(ptr [[A]], ptr @gz) | ||
; CHECK-NEXT: ret i1 false | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%a = alloca i64 | ||
%gep = getelementptr i8, ptr %a, i64 4 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an InstCombine test to demonstrate that this case can be folded using KnownBits (
??000
!=??100
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this was actually a mistake in the test. The zero-size allocation was supposed to have
align 1
. It's weird that LLVM infersalign 8
for it by default. I adjusted the test.InstCombine actually fails to handle this (see https://llvm.godbolt.org/z/WMPKdnrMd for variant without allocas) due to a weakness in foldICmpUsingKnownBits. I'll work on a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the fix: #115874