Files
clang-p2996/llvm/test/Transforms/LoopStrengthReduce/X86/expander-reused-value-insert-point.ll
Eli Friedman 7ac1c7bead Recommit [ScalarEvolution] Make getMinusSCEV() fail for unrelated pointers.
As part of making ScalarEvolution's handling of pointers consistent, we
want to forbid multiplying a pointer by -1 (or any other value). This
means we can't blindly subtract pointers.

There are a few ways we could deal with this:
1. We could completely forbid subtracting pointers in getMinusSCEV()
2. We could forbid subracting pointers with different pointer bases
(this patch).
3. We could try to ptrtoint pointer operands.

The option in this patch is more friendly to non-integral pointers: code
that works with normal pointers will also work with non-integral
pointers. And it seems like there are very few places that actually
benefit from the third option.

As a minimal patch, the ScalarEvolution implementation of getMinusSCEV
still ends up subtracting pointers if they have the same base.  This
should eliminate the shared pointer base, but eventually we'll need to
rewrite it to avoid negating the pointer base. I plan to do this as a
separate step to allow measuring the compile-time impact.

This doesn't cause obvious functional changes in most cases; the one
case that is significantly affected is ICmpZero handling in LSR (which
is the source of almost all the test changes).  The resulting changes
seem okay to me, but suggestions welcome.  As an alternative, I tried
explicitly ptrtoint'ing the operands, but the result doesn't seem
obviously better.

I deleted the test lsr-undef-in-binop.ll becuase I couldn't figure out
how to repair it to test what it was actually trying to test.

Recommitting with fix to MemoryDepChecker::isDependent.

Differential Revision: https://reviews.llvm.org/D104806
2021-07-06 12:16:05 -07:00

66 lines
3.0 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -loop-reduce -S %s | FileCheck %s
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"
declare void @use(double) readnone
; Make sure re-used instructions do not impact the insertion points for SCEV
; expansion.
define void @test(double* %ioptr, i32 %X, double* %start, double* %end) {
; CHECK-LABEL: @test(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[IDX_EXT32:%.*]] = sext i32 [[X:%.*]] to i64
; CHECK-NEXT: [[TMP0:%.*]] = shl nsw i64 [[IDX_EXT32]], 3
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[TMP0]], 8
; CHECK-NEXT: br label [[FOR_BODY15:%.*]]
; CHECK: for.body15:
; CHECK-NEXT: br label [[FOR_BODY37:%.*]]
; CHECK: for.body37:
; CHECK-NEXT: [[P0R_0335:%.*]] = phi double* [ [[ADD_PTR94:%.*]], [[FOR_BODY37]] ], [ [[START:%.*]], [[FOR_BODY15]] ]
; CHECK-NEXT: [[ADD_PTR94]] = getelementptr inbounds double, double* [[P0R_0335]], i64 1
; CHECK-NEXT: [[P0R_03351:%.*]] = bitcast double* [[P0R_0335]] to i8*
; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, i8* [[P0R_03351]], i64 [[TMP1]]
; CHECK-NEXT: [[UGLYGEP2:%.*]] = bitcast i8* [[UGLYGEP]] to double*
; CHECK-NEXT: [[F1I_0:%.*]] = load double, double* [[UGLYGEP2]], align 8
; CHECK-NEXT: call void @use(double [[F1I_0]])
; CHECK-NEXT: [[EC0:%.*]] = icmp eq double* [[ADD_PTR94]], [[END:%.*]]
; CHECK-NEXT: br i1 [[EC0]], label [[FOR_BODY37]], label [[FOR_END_LOOPEXIT:%.*]]
; CHECK: for.end.loopexit:
; CHECK-NEXT: br label [[FOR_END:%.*]]
; CHECK: for.end:
; CHECK-NEXT: [[P0R_0_LCSSA:%.*]] = phi double* [ [[ADD_PTR94]], [[FOR_END_LOOPEXIT]] ]
; CHECK-NEXT: [[EC1:%.*]] = icmp eq double* [[P0R_0_LCSSA]], [[END]]
; CHECK-NEXT: br i1 [[EC1]], label [[FOR_BODY15]], label [[FOR_INC133:%.*]]
; CHECK: for.inc133:
; CHECK-NEXT: ret void
;
entry:
%idx.ext32 = sext i32 %X to i64
br label %for.body15
for.body15: ; preds = %for.end, %for.body15.lr.ph
br label %for.body37
for.body37: ; preds = %for.body37, %for.body37.preheader
%p0r.0335 = phi double* [ %add.ptr94, %for.body37 ], [ %start, %for.body15 ]
%add.ptr94 = getelementptr inbounds double, double* %p0r.0335, i64 1
%f1i.0.in = getelementptr inbounds double, double* %add.ptr94, i64 %idx.ext32
%f1i.0 = load double, double* %f1i.0.in, align 8
call void @use(double %f1i.0)
%ec0 = icmp eq double* %add.ptr94, %end
br i1 %ec0, label %for.body37, label %for.end.loopexit
for.end.loopexit: ; preds = %for.body37
br label %for.end
for.end: ; preds = %for.end.loopexit, %for.body15
%p0r.0.lcssa = phi double* [ %add.ptr94, %for.end.loopexit ]
%ec1 = icmp eq double* %p0r.0.lcssa, %end
br i1 %ec1, label %for.body15, label %for.inc133
for.inc133: ; preds = %for.end
ret void
}