Skip to content

Commit 78b8ce4

Browse files
committed
Reland [SCEV] Improve modelling for (null) pointer constants
This reverts commit 329aeb5, and relands commit 61f006a. This is a continuation of D89456. As it was suggested there, now that SCEV models `PtrToInt`, we can try to improve SCEV's pointer handling. In particular, i believe, i will need this in the future to further fix `SCEVAddExpr`operation type handling. This removes special handling of `ConstantPointerNull` from `ScalarEvolution::createSCEV()`, and add constant folding into `ScalarEvolution::getPtrToIntExpr()`. This way, `null` constants stay as such in SCEV's, but gracefully become zero integers when asked. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D98147
1 parent 6e9b997 commit 78b8ce4

22 files changed

+276
-207
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,15 +1065,23 @@ const SCEV *ScalarEvolution::getPtrToIntExpr(const SCEV *Op, Type *Ty,
10651065
return getTruncateOrZeroExtend(S, Ty);
10661066

10671067
// If not, is this expression something we can't reduce any further?
1068-
if (isa<SCEVUnknown>(Op)) {
1069-
// Create an explicit cast node.
1070-
// We can reuse the existing insert position since if we get here,
1071-
// we won't have made any changes which would invalidate it.
1068+
if (auto *U = dyn_cast<SCEVUnknown>(Op)) {
10721069
Type *IntPtrTy = getDataLayout().getIntPtrType(Op->getType());
10731070
assert(getDataLayout().getTypeSizeInBits(getEffectiveSCEVType(
10741071
Op->getType())) == getDataLayout().getTypeSizeInBits(IntPtrTy) &&
10751072
"We can only model ptrtoint if SCEV's effective (integer) type is "
10761073
"sufficiently wide to represent all possible pointer values.");
1074+
1075+
// Perform some basic constant folding. If the operand of the ptr2int cast
1076+
// is a null pointer, don't create a ptr2int SCEV expression (that will be
1077+
// left as-is), but produce a zero constant.
1078+
// NOTE: We could handle a more general case, but lack motivational cases.
1079+
if (isa<ConstantPointerNull>(U->getValue()))
1080+
return getZero(Ty);
1081+
1082+
// Create an explicit cast node.
1083+
// We can reuse the existing insert position since if we get here,
1084+
// we won't have made any changes which would invalidate it.
10771085
SCEV *S = new (SCEVAllocator)
10781086
SCEVPtrToIntExpr(ID.Intern(SCEVAllocator), Op, IntPtrTy);
10791087
UniqueSCEVs.InsertNode(S, IP);
@@ -6366,9 +6374,6 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
63666374
return getUnknown(UndefValue::get(V->getType()));
63676375
} else if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
63686376
return getConstant(CI);
6369-
else if (isa<ConstantPointerNull>(V))
6370-
// FIXME: we shouldn't special-case null pointer constant.
6371-
return getZero(V->getType());
63726377
else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
63736378
return GA->isInterposable() ? getUnknown(V) : getSCEV(GA->getAliasee());
63746379
else if (!isa<ConstantExpr>(V))
@@ -6708,11 +6713,6 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
67086713
Value *Ptr = U->getOperand(0);
67096714
const SCEV *Op = getSCEV(Ptr);
67106715
Type *DstIntTy = U->getType();
6711-
// SCEV doesn't have constant pointer expression type, but it supports
6712-
// nullptr constant (and only that one), which is modelled in SCEV as a
6713-
// zero integer constant. So just skip the ptrtoint cast for constants.
6714-
if (isa<SCEVConstant>(Op))
6715-
return getTruncateOrZeroExtend(Op, DstIntTy);
67166716
Type *PtrTy = Ptr->getType();
67176717
Type *IntPtrTy = getDataLayout().getIntPtrType(PtrTy);
67186718
// But only if effective SCEV (integer) type is wide enough to represent

llvm/test/Analysis/ScalarEvolution/load.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ define i32 @test2() nounwind uwtable readonly {
8282
; CHECK-NEXT: %next = getelementptr inbounds %struct.ListNode, %struct.ListNode* %n.01, i64 0, i32 0
8383
; CHECK-NEXT: --> %n.01 U: full-set S: full-set Exits: @node1 LoopDispositions: { %for.body: Variant }
8484
; CHECK-NEXT: %1 = load %struct.ListNode*, %struct.ListNode** %next, align 8
85-
; CHECK-NEXT: --> %1 U: full-set S: full-set Exits: 0 LoopDispositions: { %for.body: Variant }
85+
; CHECK-NEXT: --> %1 U: full-set S: full-set Exits: null LoopDispositions: { %for.body: Variant }
8686
; CHECK-NEXT: Determining loop execution counts for: @test2
8787
; CHECK-NEXT: Loop %for.body: backedge-taken count is 4
8888
; CHECK-NEXT: Loop %for.body: max backedge-taken count is 4

llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,17 @@ define void @crash(i8* %ptr) {
531531
; CHECK-LABEL: 'crash'
532532
; CHECK-NEXT: Classifying expressions for: @crash
533533
; CHECK-NEXT: %text.addr.5 = phi i8* [ %incdec.ptr112, %while.cond111 ], [ null, %while.body ]
534-
; CHECK-NEXT: --> {0,+,-1}<nw><%while.cond111> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.cond111: Computable, %while.body: Variant }
534+
; CHECK-NEXT: --> {null,+,-1}<nw><%while.cond111> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.cond111: Computable, %while.body: Variant }
535535
; CHECK-NEXT: %incdec.ptr112 = getelementptr inbounds i8, i8* %text.addr.5, i64 -1
536-
; CHECK-NEXT: --> {-1,+,-1}<nw><%while.cond111> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.cond111: Computable, %while.body: Variant }
536+
; CHECK-NEXT: --> {(-1 + null)<nuw><nsw>,+,-1}<nw><%while.cond111> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.cond111: Computable, %while.body: Variant }
537537
; CHECK-NEXT: %lastout.2271 = phi i8* [ %incdec.ptr126, %while.body125 ], [ %ptr, %while.end117 ]
538-
; CHECK-NEXT: --> {%ptr,+,1}<nuw><%while.body125> U: full-set S: full-set Exits: {-2,+,-1}<nw><%while.cond111> LoopDispositions: { %while.body125: Computable }
538+
; CHECK-NEXT: --> {%ptr,+,1}<nuw><%while.body125> U: full-set S: full-set Exits: {(-2 + null)<nuw><nsw>,+,-1}<nw><%while.cond111> LoopDispositions: { %while.body125: Computable }
539539
; CHECK-NEXT: %incdec.ptr126 = getelementptr inbounds i8, i8* %lastout.2271, i64 1
540-
; CHECK-NEXT: --> {(1 + %ptr)<nuw>,+,1}<nuw><%while.body125> U: [1,0) S: [1,0) Exits: {-1,+,-1}<nw><%while.cond111> LoopDispositions: { %while.body125: Computable }
540+
; CHECK-NEXT: --> {(1 + %ptr)<nuw>,+,1}<nuw><%while.body125> U: [1,0) S: [1,0) Exits: {(-1 + null)<nuw><nsw>,+,-1}<nw><%while.cond111> LoopDispositions: { %while.body125: Computable }
541541
; CHECK-NEXT: Determining loop execution counts for: @crash
542-
; CHECK-NEXT: Loop %while.body125: backedge-taken count is {(-2 + (-1 * %ptr)),+,-1}<nw><%while.cond111>
542+
; CHECK-NEXT: Loop %while.body125: backedge-taken count is {(-2 + (-1 * %ptr) + null),+,-1}<nw><%while.cond111>
543543
; CHECK-NEXT: Loop %while.body125: max backedge-taken count is -1
544-
; CHECK-NEXT: Loop %while.body125: Predicated backedge-taken count is {(-2 + (-1 * %ptr)),+,-1}<nw><%while.cond111>
544+
; CHECK-NEXT: Loop %while.body125: Predicated backedge-taken count is {(-2 + (-1 * %ptr) + null),+,-1}<nw><%while.cond111>
545545
; CHECK-NEXT: Predicates:
546546
; CHECK: Loop %while.body125: Trip multiple is 1
547547
; CHECK-NEXT: Loop %while.cond111: Unpredictable backedge-taken count.

llvm/test/Analysis/ScalarEvolution/scalable-vector.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define void @a(<vscale x 1 x i64> *%p) {
66
; CHECK-LABEL: 'a'
77
; CHECK-NEXT: Classifying expressions for: @a
88
; CHECK-NEXT: %1 = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* null, i32 3
9-
; CHECK-NEXT: --> (3 * sizeof(<vscale x 4 x i32>)) U: [0,-15) S: [-9223372036854775808,9223372036854775793)
9+
; CHECK-NEXT: --> ((3 * sizeof(<vscale x 4 x i32>)) + null) U: [0,-15) S: [-9223372036854775808,9223372036854775793)
1010
; CHECK-NEXT: %2 = getelementptr <vscale x 1 x i64>, <vscale x 1 x i64>* %p, i32 1
1111
; CHECK-NEXT: --> (sizeof(<vscale x 1 x i64>) + %p) U: full-set S: full-set
1212
; CHECK-NEXT: Determining loop execution counts for: @a

llvm/test/CodeGen/AMDGPU/splitkit-getsubrangeformask.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ define amdgpu_gs void @_amdgpu_gs_main(i32 inreg %primShaderTableAddrLow, <31 x
185185
; CHECK: [[S_ADD_I32_15:%[0-9]+]]:sreg_32 = S_ADD_I32 [[S_BUFFER_LOAD_DWORD_IMM4]], -467, implicit-def dead $scc
186186
; CHECK: undef %453.sub0:sreg_64 = S_ADD_U32 [[S_ADD_U32_4]], [[S_LSHL_B32_6]], implicit-def $scc
187187
; CHECK: %453.sub1:sreg_64 = S_ADDC_U32 [[S_ADDC_U32_4]], [[S_ASHR_I32_6]], implicit-def dead $scc, implicit $scc
188-
; CHECK: %71.sub0_sub1:sgpr_128 = S_LOAD_DWORDX2_IMM %453, 0, 0, 0 :: (load 8 from %ir.304, addrspace 4)
188+
; CHECK: %71.sub0_sub1:sgpr_128 = S_LOAD_DWORDX2_IMM %453, 0, 0, 0 :: (load 8 from %ir.308, addrspace 4)
189189
; CHECK: [[BUFFER_LOAD_DWORD_OFFSET3:%[0-9]+]]:vgpr_32 = BUFFER_LOAD_DWORD_OFFSET [[S_LOAD_DWORDX4_IMM18]], 0, 0, 0, 0, 0, 0, 0, 0, implicit $exec :: (dereferenceable load 4 from custom "BufferResource", align 1, addrspace 4)
190190
; CHECK: [[S_LOAD_DWORDX4_IMM19:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %327, 0, 0, 0 :: (load 16 from %ir.223, addrspace 4)
191191
; CHECK: [[S_LOAD_DWORDX4_IMM20:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %335, 0, 0, 0 :: (load 16 from %ir.230, addrspace 4)
@@ -202,16 +202,16 @@ define amdgpu_gs void @_amdgpu_gs_main(i32 inreg %primShaderTableAddrLow, <31 x
202202
; CHECK: [[S_ADD_I32_16:%[0-9]+]]:sreg_32 = S_ADD_I32 [[S_BUFFER_LOAD_DWORD_IMM5]], -468, implicit-def dead $scc
203203
; CHECK: undef %468.sub0:sreg_64 = S_ADD_U32 [[S_ADD_U32_4]], [[S_LSHL_B32_7]], implicit-def $scc
204204
; CHECK: %468.sub1:sreg_64 = S_ADDC_U32 [[S_ADDC_U32_4]], [[S_ASHR_I32_7]], implicit-def dead $scc, implicit $scc
205-
; CHECK: %71.sub0_sub1:sgpr_128 = S_LOAD_DWORDX2_IMM %468, 0, 0, 0 :: (load 8 from %ir.316, addrspace 4)
205+
; CHECK: %71.sub0_sub1:sgpr_128 = S_LOAD_DWORDX2_IMM %468, 0, 0, 0 :: (load 8 from %ir.320, addrspace 4)
206206
; CHECK: %71.sub1:sgpr_128 = S_AND_B32 %71.sub1, [[S_MOV_B32_]], implicit-def dead $scc
207207
; CHECK: [[S_BUFFER_LOAD_DWORD_IMM6:%[0-9]+]]:sreg_32_xm0_xexec = S_BUFFER_LOAD_DWORD_IMM %71, 0, 0, 0 :: (dereferenceable invariant load 4)
208-
; CHECK: [[S_LOAD_DWORDX4_IMM23:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %411, 0, 0, 0 :: (load 16 from %ir.278, addrspace 4)
208+
; CHECK: [[S_LOAD_DWORDX4_IMM23:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %411, 0, 0, 0 :: (load 16 from %ir.282, addrspace 4)
209209
; CHECK: [[S_LOAD_DWORD_IMM:%[0-9]+]]:sreg_32_xm0_xexec = S_LOAD_DWORD_IMM undef %488:sreg_64, 0, 0, 0 :: (load 4 from `i32 addrspace(4)* undef`, addrspace 4)
210210
; CHECK: KILL %411.sub0, %411.sub1
211211
; CHECK: KILL undef %488:sreg_64
212212
; CHECK: KILL %71.sub0_sub1
213213
; CHECK: [[S_LSHL_B32_8:%[0-9]+]]:sreg_32 = S_LSHL_B32 [[COPY11]], 3, implicit-def dead $scc
214-
; CHECK: [[S_LOAD_DWORDX4_IMM24:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %425, 0, 0, 0 :: (load 16 from %ir.287, addrspace 4)
214+
; CHECK: [[S_LOAD_DWORDX4_IMM24:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %425, 0, 0, 0 :: (load 16 from %ir.291, addrspace 4)
215215
; CHECK: [[S_ASHR_I32_8:%[0-9]+]]:sreg_32_xm0 = S_ASHR_I32 [[S_LSHL_B32_8]], 31, implicit-def dead $scc
216216
; CHECK: [[S_ADD_I32_17:%[0-9]+]]:sreg_32 = S_ADD_I32 [[S_BUFFER_LOAD_DWORD_IMM6]], -469, implicit-def dead $scc
217217
; CHECK: undef %485.sub0:sreg_64 = S_ADD_U32 [[S_ADD_U32_4]], [[S_LSHL_B32_8]], implicit-def $scc
@@ -234,13 +234,13 @@ define amdgpu_gs void @_amdgpu_gs_main(i32 inreg %primShaderTableAddrLow, <31 x
234234
; CHECK: [[S_ADDC_U32_5:%[0-9]+]]:sreg_32 = S_ADDC_U32 undef %33:sreg_32, 0, implicit-def dead $scc, implicit $scc
235235
; CHECK: undef %514.sub0:sreg_64 = S_ADD_U32 [[S_ADD_U32_5]], [[S_LSHL_B32_]], implicit-def $scc
236236
; CHECK: %514.sub1:sreg_64 = S_ADDC_U32 [[S_ADDC_U32_5]], [[S_ASHR_I32_]], implicit-def dead $scc, implicit $scc
237-
; CHECK: [[S_LOAD_DWORDX4_IMM25:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %514, 0, 0, 0 :: (load 16 from %ir.347, addrspace 4)
237+
; CHECK: [[S_LOAD_DWORDX4_IMM25:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %514, 0, 0, 0 :: (load 16 from %ir.351, addrspace 4)
238238
; CHECK: undef %522.sub0:sreg_64 = S_ADD_U32 [[S_ADD_U32_5]], [[S_LSHL_B32_1]], implicit-def $scc
239239
; CHECK: %522.sub1:sreg_64 = S_ADDC_U32 [[S_ADDC_U32_5]], [[S_ASHR_I32_1]], implicit-def dead $scc, implicit $scc
240-
; CHECK: [[S_LOAD_DWORDX4_IMM26:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %522, 0, 0, 0 :: (load 16 from %ir.353, addrspace 4)
240+
; CHECK: [[S_LOAD_DWORDX4_IMM26:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %522, 0, 0, 0 :: (load 16 from %ir.357, addrspace 4)
241241
; CHECK: undef %530.sub0:sreg_64 = S_ADD_U32 [[S_ADD_U32_5]], [[S_LSHL_B32_2]], implicit-def $scc
242242
; CHECK: %530.sub1:sreg_64 = S_ADDC_U32 [[S_ADDC_U32_5]], [[S_ASHR_I32_2]], implicit-def dead $scc, implicit $scc
243-
; CHECK: [[S_LOAD_DWORDX4_IMM27:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %530, 0, 0, 0 :: (load 16 from %ir.359, addrspace 4)
243+
; CHECK: [[S_LOAD_DWORDX4_IMM27:%[0-9]+]]:sgpr_128 = S_LOAD_DWORDX4_IMM %530, 0, 0, 0 :: (load 16 from %ir.363, addrspace 4)
244244
; CHECK: [[BUFFER_LOAD_FORMAT_X_IDXEN23:%[0-9]+]]:vgpr_32 = BUFFER_LOAD_FORMAT_X_IDXEN [[V_MOV_B32_e32_]], [[S_LOAD_DWORDX4_IMM25]], 0, 0, 0, 0, 0, 0, 0, 0, implicit $exec :: (dereferenceable load 4 from custom "BufferResource", align 1, addrspace 4)
245245
; CHECK: [[BUFFER_LOAD_FORMAT_X_IDXEN24:%[0-9]+]]:vgpr_32 = BUFFER_LOAD_FORMAT_X_IDXEN [[V_MOV_B32_e32_]], [[S_LOAD_DWORDX4_IMM26]], 0, 0, 0, 0, 0, 0, 0, 0, implicit $exec :: (dereferenceable load 4 from custom "BufferResource", align 1, addrspace 4)
246246
; CHECK: [[BUFFER_LOAD_FORMAT_X_IDXEN25:%[0-9]+]]:vgpr_32 = BUFFER_LOAD_FORMAT_X_IDXEN [[V_MOV_B32_e32_]], [[S_LOAD_DWORDX4_IMM27]], 0, 0, 0, 0, 0, 0, 0, 0, implicit $exec :: (dereferenceable load 4 from custom "BufferResource", align 1, addrspace 4)

llvm/test/CodeGen/PowerPC/pr43527.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ define dso_local void @test(i64 %arg, i64 %arg1) {
1919
; CHECK-NEXT: std r0, 16(r1)
2020
; CHECK-NEXT: stdu r1, -64(r1)
2121
; CHECK-NEXT: sub r30, r4, r3
22-
; CHECK-NEXT: li r29, 0
22+
; CHECK-NEXT: li r29, -4
2323
; CHECK-NEXT: .p2align 5
2424
; CHECK-NEXT: .LBB0_3: # %bb5
2525
; CHECK-NEXT: #
26-
; CHECK-NEXT: lfsx f1, 0, r29
26+
; CHECK-NEXT: lfsu f1, 4(r29)
2727
; CHECK-NEXT: bl lrint
2828
; CHECK-NEXT: nop
2929
; CHECK-NEXT: addi r30, r30, -1
30-
; CHECK-NEXT: addi r29, r29, 4
3130
; CHECK-NEXT: cmpldi r30, 0
3231
; CHECK-NEXT: bne cr0, .LBB0_3
3332
; CHECK-NEXT: # %bb.4: # %bb15

llvm/test/CodeGen/PowerPC/pr48519.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,17 @@ define void @func_48785(half %arg) #0 {
265265
; CHECK-NEXT: stdu r1, -64(r1)
266266
; CHECK-NEXT: fmr f31, f1
267267
; CHECK-NEXT: li r30, 0
268+
; CHECK-NEXT: li r29, 0
268269
; CHECK-NEXT: .p2align 5
269270
; CHECK-NEXT: .LBB3_1: # %bb1
270271
; CHECK-NEXT: #
271272
; CHECK-NEXT: fmr f1, f31
272-
; CHECK-NEXT: sldi r29, r30, 1
273273
; CHECK-NEXT: bl __gnu_f2h_ieee
274274
; CHECK-NEXT: nop
275-
; CHECK-NEXT: addi r30, r30, 12
276-
; CHECK-NEXT: sth r3, 0(r29)
277-
; CHECK-NEXT: cmpldi r30, 0
275+
; CHECK-NEXT: addi r29, r29, -12
276+
; CHECK-NEXT: sth r3, 0(r30)
277+
; CHECK-NEXT: addi r30, r30, 24
278+
; CHECK-NEXT: cmpldi r29, 0
278279
; CHECK-NEXT: bne+ cr0, .LBB3_1
279280
; CHECK-NEXT: # %bb.2: # %bb5
280281
;

llvm/test/CodeGen/PowerPC/sms-phi.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
; RUN: >/dev/null | FileCheck %s
55
define dso_local void @sha512() #0 {
66
;CHECK: prolog:
7-
;CHECK: %16:g8rc = ADD8 %21:g8rc, %20:g8rc
7+
;CHECK: %18:g8rc = ADD8 %24:g8rc, %23:g8rc
88
;CHECK: epilog:
9-
;CHECK: %23:g8rc_and_g8rc_nox0 = PHI %5:g8rc_and_g8rc_nox0, %bb.3, %18:g8rc_and_g8rc_nox0, %bb.4
10-
;CHECK-NEXT: %24:g8rc = PHI %6:g8rc, %bb.3, %16:g8rc, %bb.4
11-
;CHECK-NEXT: %25:g8rc = PHI %6:g8rc, %bb.3, %19:g8rc, %bb.4
9+
;CHECK: %28:g8rc_and_g8rc_nox0 = PHI %6:g8rc_and_g8rc_nox0, %bb.3, %22:g8rc_and_g8rc_nox0, %bb.4
10+
;CHECK-NEXT: %29:g8rc = PHI %12:g8rc, %bb.3, %16:g8rc, %bb.4
11+
;CHECK-NEXT: %30:g8rc = PHI %15:g8rc, %bb.3, %19:g8rc, %bb.4
1212
br label %1
1313

1414
1: ; preds = %1, %0

llvm/test/Other/constant-fold-gep.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@
192192
; SCEV: %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
193193
; SCEV: --> (-2 + inttoptr (i32 1 to i1*))
194194
; SCEV: Classifying expressions for: @hoo8
195-
; SCEV: --> -1
195+
; SCEV: --> (-1 + null)<nuw><nsw> U: [-1,0) S: [-1,0)
196196
; SCEV: Classifying expressions for: @hoo1
197-
; SCEV: --> -1
197+
; SCEV: --> (-1 + null)<nuw><nsw> U: [-1,0) S: [-1,0)
198198

199199
define i8* @goo8() nounwind {
200200
%t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
@@ -408,13 +408,13 @@ define i64 @fi() nounwind {
408408
; TO: }
409409
; SCEV: Classifying expressions for: @fM
410410
; SCEV: %t = bitcast i64* getelementptr (i64, i64* null, i32 1) to i64*
411-
; SCEV: --> 8
411+
; SCEV: --> (8 + null)<nuw><nsw> U: [8,9) S: [8,9)
412412
; SCEV: Classifying expressions for: @fN
413413
; SCEV: %t = bitcast i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1) to i64*
414-
; SCEV: --> 8
414+
; SCEV: --> (8 + null)<nuw><nsw> U: [8,9) S: [8,9)
415415
; SCEV: Classifying expressions for: @fO
416416
; SCEV: %t = bitcast i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1) to i64*
417-
; SCEV: --> 8
417+
; SCEV: --> (8 + null)<nuw><nsw> U: [8,9) S: [8,9)
418418

419419
define i64* @fM() nounwind {
420420
%t = bitcast i64* getelementptr (i64, i64* null, i32 1) to i64*

llvm/test/Transforms/IndVarSimplify/2011-11-01-lftrptr.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ define i8 @testnullptrint(i8* %buf, i8* %end) nounwind {
150150
; PTR64-NEXT: [[TMP2:%.*]] = sub i32 [[TMP1]], [[BI]]
151151
; PTR64-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
152152
; PTR64-NEXT: [[TMP4:%.*]] = add nuw nsw i64 [[TMP3]], 1
153-
; PTR64-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to i8*
153+
; PTR64-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* null, i64 [[TMP4]]
154154
; PTR64-NEXT: br label [[LOOP:%.*]]
155155
; PTR64: loop:
156156
; PTR64-NEXT: [[P_01_US_US:%.*]] = phi i8* [ null, [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
157157
; PTR64-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
158158
; PTR64-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]], align 1
159-
; PTR64-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[TMP5]]
159+
; PTR64-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[SCEVGEP]]
160160
; PTR64-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
161161
; PTR64: exit.loopexit:
162162
; PTR64-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
@@ -171,16 +171,16 @@ define i8 @testnullptrint(i8* %buf, i8* %end) nounwind {
171171
; PTR32-NEXT: [[BI:%.*]] = ptrtoint i8* [[BUF:%.*]] to i32
172172
; PTR32-NEXT: [[EI:%.*]] = ptrtoint i8* [[END:%.*]] to i32
173173
; PTR32-NEXT: [[CNT:%.*]] = sub i32 [[EI]], [[BI]]
174-
; PTR32-NEXT: [[CNT1:%.*]] = inttoptr i32 [[CNT]] to i8*
175174
; PTR32-NEXT: [[GUARD:%.*]] = icmp ult i32 0, [[CNT]]
176175
; PTR32-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
177176
; PTR32: preheader:
177+
; PTR32-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* null, i32 [[CNT]]
178178
; PTR32-NEXT: br label [[LOOP:%.*]]
179179
; PTR32: loop:
180180
; PTR32-NEXT: [[P_01_US_US:%.*]] = phi i8* [ null, [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
181181
; PTR32-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
182182
; PTR32-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]], align 1
183-
; PTR32-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[CNT1]]
183+
; PTR32-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[SCEVGEP]]
184184
; PTR32-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
185185
; PTR32: exit.loopexit:
186186
; PTR32-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]

llvm/test/Transforms/IndVarSimplify/widen-i32-i8ptr.ll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ define dso_local void @Widen_i32_i8ptr() local_unnamed_addr {
1111
; CHECK-NEXT: store i8** [[ARRAYDECAY2032]], i8*** inttoptr (i64 8 to i8***), align 8
1212
; CHECK-NEXT: br label [[FOR_COND2106:%.*]]
1313
; CHECK: for.cond2106:
14-
; CHECK-NEXT: [[GID_0:%.*]] = phi i8* [ null, [[ENTRY:%.*]] ], [ [[INCDEC_PTR:%.*]], [[FOR_COND2106]] ]
15-
; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC2117:%.*]], [[FOR_COND2106]] ]
14+
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_COND2106]] ], [ 0, [[ENTRY:%.*]] ]
15+
; CHECK-NEXT: [[GID_0:%.*]] = phi i8* [ null, [[ENTRY]] ], [ [[INCDEC_PTR:%.*]], [[FOR_COND2106]] ]
1616
; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, i8* [[GID_0]], i64 1
17-
; CHECK-NEXT: [[IDXPROM2114:%.*]] = zext i32 [[I_0]] to i64
18-
; CHECK-NEXT: [[ARRAYIDX2115:%.*]] = getelementptr inbounds [15 x i8*], [15 x i8*]* [[PTRIDS]], i64 0, i64 [[IDXPROM2114]]
17+
; CHECK-NEXT: [[ARRAYIDX2115:%.*]] = getelementptr inbounds [15 x i8*], [15 x i8*]* [[PTRIDS]], i64 0, i64 [[INDVARS_IV]]
1918
; CHECK-NEXT: store i8* [[GID_0]], i8** [[ARRAYIDX2115]], align 8
20-
; CHECK-NEXT: [[INC2117]] = add nuw nsw i32 [[I_0]], 1
19+
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw i64 [[INDVARS_IV]], 1
2120
; CHECK-NEXT: br label [[FOR_COND2106]]
2221
;
2322
entry:

0 commit comments

Comments
 (0)