[llvm] [SROA] Unfold gep of index select (PR #80983)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 11:45:06 PST 2024


================
@@ -202,8 +206,10 @@ define i32 @test_select_idx_escaped(i1 %c, ptr %p) {
 ; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 24
 ; CHECK-NEXT:    store i32 2, ptr [[GEP1]], align 4
 ; CHECK-NEXT:    [[IDX:%.*]] = select i1 [[C:%.*]], i64 24, i64 0
-; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 [[IDX]]
-; CHECK-NEXT:    [[RES:%.*]] = load i32, ptr [[GEP2]], align 4
+; CHECK-NEXT:    [[DOTSROA_GEP:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 24
+; CHECK-NEXT:    [[DOTSROA_GEP1:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 0
+; CHECK-NEXT:    [[IDX_SROA_SEL:%.*]] = select i1 [[C]], ptr [[DOTSROA_GEP]], ptr [[DOTSROA_GEP1]]
+; CHECK-NEXT:    [[RES:%.*]] = load i32, ptr [[IDX_SROA_SEL]], align 4
----------------
Artem-B wrote:

Looks like 'transactional' way of transforming basic blocks or functions might be a useful concept. 
E.g. a pass may attempt to do some transformation but does not know ahead of time if it will succeed. If it works out, keep the new block, if not, restore the original version.
I'm surprised we do not have it as a standard feature in LLVM. Or, maybe we do?  In any case, that's a subject for a separate conversation.


https://github.com/llvm/llvm-project/pull/80983


More information about the llvm-commits mailing list