
Currently, SROA is CFG-preserving. Not doing so does not affect any pipeline test. (???) Internally, SROA requires Dominator Tree, and uses it solely for the final `-mem2reg` call. By design, we can't really SROA alloca if their address escapes somehow, but we have logic to deal with `load` of `select`/`PHI`, where at least one of the possible addresses prevents promotion, by speculating the `load`s and `select`ing between loaded values. As one would expect, that requires ensuring that the speculation is actually legal. Even ignoring complexity bailouts, that logic does not deal with everything, e.g. `isSafeToLoadUnconditionally()` does not recurse into hands of `select`. There can also be cases where the load is genuinely non-speculate. So if we can't prove that the load can be speculated, unfold the select, produce two-entry phi node, and perform predicated load. Now, that transformation must obviously update Dominator Tree, since we require it later on. Doing so is trivial. Additionally, we don't want to do this for the final SROA invocation (D136806). In the end, this ends up having negative (!) compile-time cost: https://llvm-compile-time-tracker.com/compare.php?from=c6d7e80ec4c17a415673b1cfd25924f98ac83608&to=ddf9600365093ea50d7e278696cbfa01641c959d&stat=instructions:u Though indeed, this only deals with `select`s, `PHI`s are still using speculation. Should we update some more analysis? Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D138238 This reverts commit 739611870d3b06605afe25cc07833f6a62de9545, and recommits 03e6d9d9d1d48e43f3efc35eb75369b90d4510d5 with a fixed assertion - we should check that DTU is there, not just assert false...
85 lines
3.3 KiB
LLVM
85 lines
3.3 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes='sroa<preserve-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-PRESERVE-CFG
|
|
; RUN: opt < %s -passes='sroa<modify-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-MODIFY-CFG
|
|
target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32:64-S128"
|
|
target triple = "sparcv9-sun-solaris"
|
|
|
|
; PR37267
|
|
; Check that we don't crash on this test.
|
|
|
|
define i16 @f1() {
|
|
; CHECK-LABEL: @f1(
|
|
; CHECK-NEXT: bb1:
|
|
; CHECK-NEXT: [[RC:%.*]] = add i16 2, 2
|
|
; CHECK-NEXT: ret i16 [[RC]]
|
|
;
|
|
bb1:
|
|
; This 12-byte alloca is split into partitions as [0,2), [2,4), [4,8), [8,10), [10, 12).
|
|
; The reported error happened when rewriteIntegerStore try to widen a split tail of slice 1 for [4, 8) partition.
|
|
; alloca 012345678901
|
|
; slice 1: WWWW
|
|
; slice 2: WWWW
|
|
; slice 3: RR
|
|
; slice 4: RR
|
|
|
|
%a.3 = alloca [6 x i16], align 1
|
|
; slice 1: [2,6)
|
|
%_tmp3 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 1
|
|
store i32 131074, ptr %_tmp3, align 1
|
|
; slice 2: [8,12)
|
|
%_tmp8 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 4
|
|
store i32 131074, ptr %_tmp8, align 1
|
|
; slice 3: [8,10)
|
|
%_tmp12 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 4
|
|
%_tmp13 = load i16, ptr %_tmp12, align 1
|
|
; slice 4: [2,4)
|
|
%_tmp15 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 1
|
|
%_tmp16 = load i16, ptr %_tmp15, align 1
|
|
|
|
%rc = add i16 %_tmp13, %_tmp16
|
|
ret i16 %rc
|
|
}
|
|
|
|
define i16 @f2() {
|
|
; CHECK-LABEL: @f2(
|
|
; CHECK-NEXT: bb1:
|
|
; CHECK-NEXT: [[A_3_SROA_2_2_INSERT_EXT:%.*]] = zext i16 undef to i32
|
|
; CHECK-NEXT: [[A_3_SROA_2_2_INSERT_MASK:%.*]] = and i32 undef, -65536
|
|
; CHECK-NEXT: [[A_3_SROA_2_2_INSERT_INSERT:%.*]] = or i32 [[A_3_SROA_2_2_INSERT_MASK]], [[A_3_SROA_2_2_INSERT_EXT]]
|
|
; CHECK-NEXT: [[A_3_SROA_0_2_INSERT_EXT:%.*]] = zext i16 undef to i32
|
|
; CHECK-NEXT: [[A_3_SROA_0_2_INSERT_SHIFT:%.*]] = shl i32 [[A_3_SROA_0_2_INSERT_EXT]], 16
|
|
; CHECK-NEXT: [[A_3_SROA_0_2_INSERT_MASK:%.*]] = and i32 [[A_3_SROA_2_2_INSERT_INSERT]], 65535
|
|
; CHECK-NEXT: [[A_3_SROA_0_2_INSERT_INSERT:%.*]] = or i32 [[A_3_SROA_0_2_INSERT_MASK]], [[A_3_SROA_0_2_INSERT_SHIFT]]
|
|
; CHECK-NEXT: [[RC:%.*]] = add i16 2, undef
|
|
; CHECK-NEXT: ret i16 [[RC]]
|
|
;
|
|
bb1:
|
|
; This 12-byte alloca is split into partitions as [0,2), [2,4), [4,8), [8,10), [10, 12).
|
|
; The reported error happened when visitLoadInst rewrites a split tail of slice 1 for [4, 8) partition.
|
|
; alloca 012345678901
|
|
; slice 1: RRRR
|
|
; slice 2: WWWW
|
|
; slice 3: RR
|
|
; slice 4: RR
|
|
|
|
%a.3 = alloca [6 x i16], align 1
|
|
; slice 1: [2,6)
|
|
%_tmp3 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 1
|
|
%_tmp6 = load i32, ptr %_tmp3, align 1
|
|
; slice 2: [8,12)
|
|
%_tmp8 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 4
|
|
store i32 131074, ptr %_tmp8, align 1
|
|
; slice 3: [8,10)
|
|
%_tmp12 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 4
|
|
%_tmp13 = load i16, ptr %_tmp12, align 1
|
|
; slice 4: [2,4)
|
|
%_tmp15 = getelementptr inbounds [6 x i16], ptr %a.3, i16 0, i16 1
|
|
%_tmp16 = load i16, ptr %_tmp15, align 1
|
|
|
|
%rc = add i16 %_tmp13, %_tmp16
|
|
ret i16 %rc
|
|
}
|
|
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
|
|
; CHECK-MODIFY-CFG: {{.*}}
|
|
; CHECK-PRESERVE-CFG: {{.*}}
|