-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[InstCombine][foldPHIArgGEPIntoPHI] Early return for const vector index for gep inst. #138661
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 2 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
%vec = type { %vec_base } | ||
%vec_base = type { [4 x float] } | ||
%foo = type { %vec, %vec} | ||
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. It is possible to simplify the GEP type a bit? I don't think you need all of these levels of nesting. All you really need is a struct index using a vector. 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. done, thanks. |
||
|
||
define void @test(i1 %tobool, ptr addrspace(1) %add.ptr) { | ||
; CHECK-LABEL: define void @test( | ||
; CHECK-SAME: i1 [[TOBOOL:%.*]], ptr addrspace(1) [[ADD_PTR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[LANE_0:%.*]] = alloca [[FOO:%.*]], align 16 | ||
; CHECK-NEXT: [[LANE_15:%.*]] = insertelement <16 x ptr> poison, ptr [[LANE_0]], i64 0 | ||
; CHECK-NEXT: br i1 [[TOBOOL]], label %[[F1:.*]], label %[[F0:.*]] | ||
; CHECK: [[F0]]: | ||
; CHECK-NEXT: [[MM_VECTORGEP:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> zeroinitializer, <16 x i32> splat (i32 1), <16 x i32> zeroinitializer, <16 x i32> zeroinitializer, <16 x i64> splat (i64 1) | ||
; CHECK-NEXT: br label %[[MERGE:.*]] | ||
; CHECK: [[F1]]: | ||
; CHECK-NEXT: [[MM_VECTORGEP2:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> zeroinitializer, <16 x i32> zeroinitializer, <16 x i32> zeroinitializer, <16 x i32> zeroinitializer, <16 x i64> splat (i64 1) | ||
; CHECK-NEXT: br label %[[MERGE]] | ||
; CHECK: [[MERGE]]: | ||
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP]], %[[F0]] ], [ [[MM_VECTORGEP2]], %[[F1]] ] | ||
; CHECK-NEXT: store <16 x ptr> [[VEC_PHI]], ptr addrspace(1) [[ADD_PTR]], align 128 | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%lane.0 = alloca %foo, align 16 | ||
%lane.15 = insertelement <16 x ptr> poison, ptr %lane.0, i64 0 | ||
%mm_vectorGEP = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> splat (i32 1), <16 x i32> zeroinitializer, <16 x i32> zeroinitializer, <16 x i64> splat (i64 1) | ||
%mm_vectorGEP2 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> zeroinitializer, <16 x i32> zeroinitializer, <16 x i32> zeroinitializer, <16 x i64> splat (i64 1) | ||
br i1 %tobool, label %f1, label %f0 | ||
|
||
f0: | ||
br label %merge | ||
|
||
f1: | ||
br label %merge | ||
|
||
merge: | ||
%vec.phi = phi <16 x ptr> [ %mm_vectorGEP, %f0], [ %mm_vectorGEP2, %f1 ] | ||
store <16 x ptr> %vec.phi, ptr addrspace(1) %add.ptr | ||
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. Can replace the store with a return. 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. done, thanks. |
||
ret void | ||
} |
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.
This ended up a bit too reduced now and no longer crashes without the change. This variant works:
(This makes sure the second GEP is not optimized away.)
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.
Thanks for your patience, updated.