-
Notifications
You must be signed in to change notification settings - Fork 397
[SwitchToIf] support multi-result scf.index_switch + add regression test #9245
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
[SwitchToIf] support multi-result scf.index_switch + add regression test #9245
Conversation
|
@cowardsa could you review it ? thanks. |
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.
LGTM - pending a small modification/question when handling the getArg return value?
Nice work on the PR otherwise - especially with the nice additional test! Once the changes are submitted tag me and I'll be able to merge for you!
| // CHECK: %[[CDEF:.*]] = arith.constant 30 : i32 | ||
| // CHECK: %[[FDEF:.*]] = arith.constant 3.000000e+00 : f32 | ||
| // CHECK: scf.yield %[[CDEF]], %[[FDEF]] : i32, f32 |
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.
Amusing observation - C default -> CDEF (just thought you'd written a string of letters)
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.
Just realizing that, Constant of the default case in my mind..
lib/Transforms/IndexSwitchToIf.cpp
Outdated
| Value switchOperand = adaptor.getArg(); | ||
| if (!switchOperand) | ||
| switchOperand = switchOp.getOperand(); |
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.
If getArg fails I would have thought this should be a failure? I.e. return failure(); as then the operator is not satisfying its definition?
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.
Good catch, I addressed that the simplest possible way @cowardsa
|
Changes look good to me - will merge once actions have run |
Motivation
Many of CIRCT’s hardware lowering paths (HW/Handshake, HLS) emit
scf.index_switchoperations whose cases drive more than one signal (e.g., a mux returning both data
and a valid flag). The existing
switch-to-ifpass only threaded the first resultthrough the nested
scf.ifchain, so multi-result switches either lost data orcrashed during conversion.
Summary of changes
lib/Transforms/IndexSwitchToIf.cppso the conversion pattern threadsthe entire result tuple through each nested
scf.if(using the adaptor’sswitch operand when available) and replaces the original switch with every
result value.
test/Transforms/switch-to-if.mlircoverage for a switch that yields(i32,f32)to ensure every result survives the transformation.