diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index a2a2d8bbb95e..705272cd73d9 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2233,32 +2233,19 @@ StrengthenNoWrapFlags(ScalarEvolution *SE, SCEVTypes Type, SignOrUnsignWrap = ScalarEvolution::maskFlags(Flags, SignOrUnsignMask); - if (SignOrUnsignWrap != SignOrUnsignMask && - (Type == scAddExpr || Type == scMulExpr) && Ops.size() == 2 && - isa(Ops[0])) { + if (SignOrUnsignWrap != SignOrUnsignMask && Type == scAddExpr && + Ops.size() == 2 && isa(Ops[0])) { - auto Opcode = [&] { - switch (Type) { - case scAddExpr: - return Instruction::Add; - case scMulExpr: - return Instruction::Mul; - default: - llvm_unreachable("Unexpected SCEV op."); - } - }(); + // (A + C) --> (A + C) if the addition does not sign overflow + // (A + C) --> (A + C) if the addition does not unsign overflow const APInt &C = cast(Ops[0])->getAPInt(); - - // (A C) --> (A C) if the op doesn't sign overflow. if (!(SignOrUnsignWrap & SCEV::FlagNSW)) { auto NSWRegion = ConstantRange::makeGuaranteedNoWrapRegion( - Opcode, C, OBO::NoSignedWrap); + Instruction::Add, C, OBO::NoSignedWrap); if (NSWRegion.contains(SE->getSignedRange(Ops[1]))) Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNSW); } - - // (A C) --> (A C) if the op doesn't unsign overflow. if (!(SignOrUnsignWrap & SCEV::FlagNUW)) { auto NUWRegion = ConstantRange::makeGuaranteedNoWrapRegion( Instruction::Add, C, OBO::NoUnsignedWrap); diff --git a/llvm/test/Analysis/Delinearization/a.ll b/llvm/test/Analysis/Delinearization/a.ll index df0e2b16f23d..a105c205c5e6 100644 --- a/llvm/test/Analysis/Delinearization/a.ll +++ b/llvm/test/Analysis/Delinearization/a.ll @@ -10,7 +10,7 @@ ; AddRec: {{{(28 + (4 * (-4 + (3 * %m)) * %o) + %A),+,(8 * %m * %o)}<%for.i>,+,(12 * %o)}<%for.j>,+,20}<%for.k> ; CHECK: Base offset: %A ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of 4 bytes. -; CHECK: ArrayRef[{3,+,2}<%for.i>][{-4,+,3}<%for.j>][{7,+,5}<%for.k>] +; CHECK: ArrayRef[{3,+,2}<%for.i>][{-4,+,3}<%for.j>][{7,+,5}<%for.k>] define void @foo(i64 %n, i64 %m, i64 %o, i32* nocapture %A) #0 { entry: diff --git a/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll b/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll index bd98d0a2b57a..bd2f34df6a16 100644 --- a/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll +++ b/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll @@ -11,7 +11,7 @@ ; AddRec: {{((%m * %b * 8) + %A),+,(2 * %m * 8)}<%for.i>,+,(2 * 8)}<%for.j> ; CHECK: Base offset: %A ; CHECK: ArrayDecl[UnknownSize][%m] with elements of 8 bytes. -; CHECK: ArrayRef[{%b,+,2}<%for.i>][{0,+,2}<%for.j>] +; CHECK: ArrayRef[{%b,+,2}<%for.i>][{0,+,2}<%for.j>] define void @foo(i64 %n, i64 %m, i64 %b, double* %A) { diff --git a/llvm/test/Analysis/IVUsers/quadradic-exit-value.ll b/llvm/test/Analysis/IVUsers/quadradic-exit-value.ll index 1597bfa8a374..afc215198218 100644 --- a/llvm/test/Analysis/IVUsers/quadradic-exit-value.ll +++ b/llvm/test/Analysis/IVUsers/quadradic-exit-value.ll @@ -70,7 +70,7 @@ exit: ; sure they aren't marked as post-inc users. ; ; CHECK-LABEL: IV Users for loop %test2.loop -; CHECK-NO-LCSSA: %sub.cond.us = ((-1 * %sub.us) + {0,+,1}<%test2.loop>) (post-inc with loop %test2.loop) in %sext.us = mul i32 %mul.us, %sub.cond.us +; CHECK-NO-LCSSA: %sub.cond.us = ((-1 * %sub.us) + {0,+,1}<%test2.loop>) (post-inc with loop %test2.loop) in %sext.us = mul i32 %mul.us, %sub.cond.us define i32 @test2() { entry: br label %test2.loop diff --git a/llvm/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll b/llvm/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll index 4528976a09e6..2bae4867870a 100644 --- a/llvm/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll +++ b/llvm/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll @@ -251,10 +251,10 @@ for.end: ; preds = %for.body ; CHECK-NEXT: Member: {((2 * %offset) + %a),+,2}<%for.body> ; CHECK-NEXT: Group {{.*}}[[ONE]]: ; CHECK-NEXT: (Low: %a High: (10000 + %a)) -; CHECK-NEXT: Member: {%a,+,2}<%for.body> +; CHECK-NEXT: Member: {%a,+,2}<%for.body> ; CHECK-NEXT: Group {{.*}}[[TWO]]: ; CHECK-NEXT: (Low: (20000 + %a) High: (30000 + %a)) -; CHECK-NEXT: Member: {(20000 + %a),+,2}<%for.body> +; CHECK-NEXT: Member: {(20000 + %a),+,2}<%for.body> define void @testi(i16* %a, i64 %offset) { diff --git a/llvm/test/Analysis/LoopAccessAnalysis/wrapping-pointer-versioning.ll b/llvm/test/Analysis/LoopAccessAnalysis/wrapping-pointer-versioning.ll index 763a5fd09b19..d448a270d96b 100644 --- a/llvm/test/Analysis/LoopAccessAnalysis/wrapping-pointer-versioning.ll +++ b/llvm/test/Analysis/LoopAccessAnalysis/wrapping-pointer-versioning.ll @@ -33,7 +33,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" ; i64 {0,+,2}<%for.body> ; LAA: [PSE] %arrayidxA = getelementptr i16, i16* %a, i64 %mul_ext: -; LAA-NEXT: ((2 * (zext i32 {0,+,2}<%for.body> to i64)) + %a) +; LAA-NEXT: ((2 * (zext i32 {0,+,2}<%for.body> to i64)) + %a) ; LAA-NEXT: --> {%a,+,4}<%for.body> @@ -130,7 +130,7 @@ for.end: ; preds = %for.body ; i64 {zext i32 (2 * (trunc i64 %N to i32)) to i64,+,-2}<%for.body> ; LAA: [PSE] %arrayidxA = getelementptr i16, i16* %a, i64 %mul_ext: -; LAA-NEXT: ((2 * (zext i32 {(2 * (trunc i64 %N to i32)),+,-2}<%for.body> to i64)) + %a) +; LAA-NEXT: ((2 * (zext i32 {(2 * (trunc i64 %N to i32)),+,-2}<%for.body> to i64)) + %a) ; LAA-NEXT: --> {((4 * (zext i31 (trunc i64 %N to i31) to i64)) + %a),+,-4}<%for.body> ; LV-LABEL: f2 diff --git a/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll b/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll index 17e7a778abb6..b54baeebf37b 100644 --- a/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll +++ b/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll @@ -322,7 +322,7 @@ define void @test_05(i32 %N) { ; CHECK: %SQ = mul i32 %i.0, %i.0 ; CHECK-NEXT: --> {4,+,5,+,2}<%bb3> ; CHECK: %tmp4 = mul i32 %i.0, 2 -; CHECK-NEXT: --> {4,+,2}<%bb3> +; CHECK-NEXT: --> {4,+,2}<%bb3> ; CHECK: %tmp5 = sub i32 %SQ, %tmp4 ; CHECK-NEXT: --> {0,+,3,+,2}<%bb3> diff --git a/llvm/test/Analysis/ScalarEvolution/mul-nuw.ll b/llvm/test/Analysis/ScalarEvolution/mul-nuw.ll deleted file mode 100644 index 4d996fb07ce9..000000000000 --- a/llvm/test/Analysis/ScalarEvolution/mul-nuw.ll +++ /dev/null @@ -1,15 +0,0 @@ -; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s - -; Check that we add nuw to multiplies by a constant where we can infer that the -; multiply does not have unsigned overflow. -declare i32 @get_int(); - -define void @foo() { - %a = call i32 @get_int(), !range !0 - %b = mul i32 %a, 4 - ; CHECK: %b - ; CHECK-NEXT: --> (4 * %a) - ret void -} - -!0 = !{i32 0, i32 100} diff --git a/llvm/test/Analysis/ScalarEvolution/nsw-offset-assume.ll b/llvm/test/Analysis/ScalarEvolution/nsw-offset-assume.ll index 3ef31ff5581b..5413b477df58 100644 --- a/llvm/test/Analysis/ScalarEvolution/nsw-offset-assume.ll +++ b/llvm/test/Analysis/ScalarEvolution/nsw-offset-assume.ll @@ -79,5 +79,5 @@ declare void @llvm.assume(i1) nounwind ; Note: Without the preheader assume, there is an 'smax' in the ; backedge-taken count expression: -; CHECK: Loop %bb: backedge-taken count is ((-1 + (2 * (%no /u 2))) /u 2) +; CHECK: Loop %bb: backedge-taken count is ((-1 + (2 * (%no /u 2))) /u 2) ; CHECK: Loop %bb: max backedge-taken count is 1073741822 diff --git a/llvm/test/Analysis/ScalarEvolution/nsw-offset.ll b/llvm/test/Analysis/ScalarEvolution/nsw-offset.ll index a5c4b575f136..f8ed8f003ff1 100644 --- a/llvm/test/Analysis/ScalarEvolution/nsw-offset.ll +++ b/llvm/test/Analysis/ScalarEvolution/nsw-offset.ll @@ -73,5 +73,5 @@ return: ; preds = %bb1.return_crit_edg ret void } -; CHECK: Loop %bb: backedge-taken count is ((-1 + (2 * (%no /u 2))) /u 2) +; CHECK: Loop %bb: backedge-taken count is ((-1 + (2 * (%no /u 2))) /u 2) ; CHECK: Loop %bb: max backedge-taken count is 1073741822 diff --git a/llvm/test/Analysis/ScalarEvolution/nsw.ll b/llvm/test/Analysis/ScalarEvolution/nsw.ll index 43e0213ec5f3..39b958d3ea0e 100644 --- a/llvm/test/Analysis/ScalarEvolution/nsw.ll +++ b/llvm/test/Analysis/ScalarEvolution/nsw.ll @@ -25,7 +25,7 @@ bb: ; preds = %bb1, %bb.nph %tmp6 = sext i32 %i.01 to i64 ; [#uses=1] %tmp7 = getelementptr double, double* %p, i64 %tmp6 ; [#uses=1] ; CHECK: %tmp7 -; CHECK-NEXT: --> {%p,+,8}<%bb> +; CHECK-NEXT: --> {%p,+,8}<%bb> store double %tmp5, double* %tmp7, align 8 %tmp8 = add nsw i32 %i.01, 1 ; [#uses=2] ; CHECK: %tmp8 @@ -126,7 +126,7 @@ exit: } ; CHECK-LABEL: PR12375 -; CHECK: --> {(4 + %arg),+,4}<%bb1>{{ U: [^ ]+ S: [^ ]+}}{{ *}}Exits: (4 + (4 * ((-1 + (-1 * %arg) + ((4 + %arg) umax (8 + %arg))) /u 4)) + %arg) +; CHECK: --> {(4 + %arg),+,4}<%bb1>{{ U: [^ ]+ S: [^ ]+}}{{ *}}Exits: (4 + (4 * ((-1 + (-1 * %arg) + ((4 + %arg) umax (8 + %arg))) /u 4)) + %arg) define i32 @PR12375(i32* readnone %arg) { bb: %tmp = getelementptr inbounds i32, i32* %arg, i64 2 @@ -145,7 +145,7 @@ bb7: ; preds = %bb1 } ; CHECK-LABEL: PR12376 -; CHECK: --> {(4 + %arg),+,4}<%bb2>{{ U: [^ ]+ S: [^ ]+}}{{ *}}Exits: (4 + (4 * ((-1 + (-1 * %arg) + ((4 + %arg) umax %arg1)) /u 4)) + %arg) +; CHECK: --> {(4 + %arg),+,4}<%bb2>{{ U: [^ ]+ S: [^ ]+}}{{ *}}Exits: (4 + (4 * ((-1 + (-1 * %arg) + ((4 + %arg) umax %arg1)) /u 4)) + %arg) define void @PR12376(i32* nocapture %arg, i32* nocapture %arg1) { bb: br label %bb2 diff --git a/llvm/test/Analysis/ScalarEvolution/sext-mul.ll b/llvm/test/Analysis/ScalarEvolution/sext-mul.ll index 88002fb0e73c..ca25d9e2efad 100644 --- a/llvm/test/Analysis/ScalarEvolution/sext-mul.ll +++ b/llvm/test/Analysis/ScalarEvolution/sext-mul.ll @@ -1,7 +1,7 @@ ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s ; CHECK: %tmp9 = shl i64 %tmp8, 33 -; CHECK-NEXT: --> {{.*}} Exits: (-8589934592 + (8589934592 * (zext i32 %arg2 to i64))) +; CHECK-NEXT: --> {{.*}} Exits: (-8589934592 + (8589934592 * (zext i32 %arg2 to i64))) ; CHECK: %tmp10 = ashr exact i64 %tmp9, 32 ; CHECK-NEXT: --> {{.*}} Exits: (sext i32 (-2 + (2 * %arg2)) to i64) ; CHECK: %tmp11 = getelementptr inbounds i32, i32* %arg, i64 %tmp10 @@ -48,9 +48,9 @@ bb7: ; preds = %bb7, %bb3 } ; CHECK: %t10 = ashr exact i128 %t9, 1 -; CHECK-NEXT: --> {{.*}} Exits: (sext i127 (-633825300114114700748351602688 + (633825300114114700748351602688 * (zext i32 %arg5 to i127))) to i128) +; CHECK-NEXT: --> {{.*}} Exits: (sext i127 (-633825300114114700748351602688 + (633825300114114700748351602688 * (zext i32 %arg5 to i127))) to i128) ; CHECK: %t14 = or i128 %t10, 1 -; CHECK-NEXT: --> {{.*}} Exits: (1 + (sext i127 (-633825300114114700748351602688 + (633825300114114700748351602688 * (zext i32 %arg5 to i127))) to i128)) +; CHECK-NEXT: --> {{.*}} Exits: (1 + (sext i127 (-633825300114114700748351602688 + (633825300114114700748351602688 * (zext i32 %arg5 to i127))) to i128)) ; CHECK: Loop %bb7: backedge-taken count is (-1 + (zext i32 %arg5 to i128)) ; CHECK-NEXT: Loop %bb7: max backedge-taken count is -1 ; CHECK-NEXT: Loop %bb7: Predicated backedge-taken count is (-1 + (zext i32 %arg5 to i128)) diff --git a/llvm/test/Analysis/ScalarEvolution/sext-zero.ll b/llvm/test/Analysis/ScalarEvolution/sext-zero.ll index 31c8e50748cd..cac42638e959 100644 --- a/llvm/test/Analysis/ScalarEvolution/sext-zero.ll +++ b/llvm/test/Analysis/ScalarEvolution/sext-zero.ll @@ -1,9 +1,9 @@ ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s ; CHECK: %tmp9 = shl i64 %tmp8, 33 -; CHECK-NEXT: --> {{.*}} Exits: (-8589934592 + (8589934592 * (zext i32 %arg2 to i64))) +; CHECK-NEXT: --> {{.*}} Exits: (-8589934592 + (8589934592 * (zext i32 %arg2 to i64))) ; CHECK-NEXT: %tmp10 = ashr exact i64 %tmp9, 0 -; CHECK-NEXT: --> {{.*}} Exits: (-8589934592 + (8589934592 * (zext i32 %arg2 to i64))) +; CHECK-NEXT: --> {{.*}} Exits: (-8589934592 + (8589934592 * (zext i32 %arg2 to i64))) define void @foo(i32* nocapture %arg, i32 %arg1, i32 %arg2) { bb: diff --git a/llvm/test/Analysis/ScalarEvolution/trip-count-pow2.ll b/llvm/test/Analysis/ScalarEvolution/trip-count-pow2.ll index 3a6f5fec2b8f..04d1b9544ab2 100644 --- a/llvm/test/Analysis/ScalarEvolution/trip-count-pow2.ll +++ b/llvm/test/Analysis/ScalarEvolution/trip-count-pow2.ll @@ -31,7 +31,7 @@ exit: ret i32 %i ; CHECK-LABEL: @test2 -; CHECK: Loop %loop: backedge-taken count is ((-32 + (32 * (%n /u 32))) /u 32) +; CHECK: Loop %loop: backedge-taken count is ((-32 + (32 * (%n /u 32))) /u 32) ; CHECK: Loop %loop: max backedge-taken count is 134217727 } diff --git a/llvm/test/Analysis/ScalarEvolution/zext-mul.ll b/llvm/test/Analysis/ScalarEvolution/zext-mul.ll index 5206613c8f26..ae93a9288d84 100644 --- a/llvm/test/Analysis/ScalarEvolution/zext-mul.ll +++ b/llvm/test/Analysis/ScalarEvolution/zext-mul.ll @@ -19,12 +19,15 @@ define void @no_range() { } ; CHECK-LABEL: @range +; +; This had to be disabled when r334428 was reverted. We should enable this test +; when r334428 is reapplied with a fix. define void @range() { %a = call i32 @get_int(), !range !0 %b = mul i32 %a, 4 %c = zext i32 %b to i64 ; CHECK: %c - ; CHECK-NEXT: --> (4 * (zext i32 %a to i64)) + ; CHECK-NEXT: --> (zext i32 (4 * %a) to i64) ret void } diff --git a/llvm/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll b/llvm/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll index 09082c61eecd..fb465a56def8 100644 --- a/llvm/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll +++ b/llvm/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll @@ -22,7 +22,7 @@ for.body153: ; preds = %for.body153, %for.b ; CHECK: add nuw nsw i64 %indvars.iv, 1 ; CHECK: sub nsw i64 %indvars.iv, 2 ; CHECK: sub nsw i64 4, %indvars.iv -; CHECK: mul nuw nsw i64 %indvars.iv, 8 +; CHECK: mul nsw i64 %indvars.iv, 8 for.body170: ; preds = %for.body170, %for.body153 %i2.19 = phi i32 [ %add249, %for.body170 ], [ 0, %for.body153 ]