Index: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp @@ -4205,10 +4205,13 @@ Changed = true; } } else { + Value* Cond = BI->getCondition(); if (BI->getSuccessor(0) == BB) { + Builder.CreateAssumption(Builder.CreateNot(Cond)); Builder.CreateBr(BI->getSuccessor(1)); EraseTerminatorAndDCECond(BI); } else if (BI->getSuccessor(1) == BB) { + Builder.CreateAssumption(Cond); Builder.CreateBr(BI->getSuccessor(0)); EraseTerminatorAndDCECond(BI); Changed = true; Index: llvm/trunk/test/Analysis/ValueTracking/select-pattern.ll =================================================================== --- llvm/trunk/test/Analysis/ValueTracking/select-pattern.ll +++ llvm/trunk/test/Analysis/ValueTracking/select-pattern.ll @@ -8,6 +8,8 @@ define void @PR36045(i1 %t, i32* %b) { ; CHECK-LABEL: @PR36045( ; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[T:%.*]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: ret void ; entry: Index: llvm/trunk/test/Transforms/CallSiteSplitting/split-loop.ll =================================================================== --- llvm/trunk/test/Transforms/CallSiteSplitting/split-loop.ll +++ llvm/trunk/test/Transforms/CallSiteSplitting/split-loop.ll @@ -5,6 +5,9 @@ ; CHECK-LABEL: @test1( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 undef, i16 1, i16 0 +; CHECK-NEXT: [[TOBOOL18:%.*]] = icmp ne i16 [[SPEC_SELECT]], 0 +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[TOBOOL18]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: br label [[FOR_COND12:%.*]] ; CHECK: for.cond12: ; CHECK-NEXT: call void @callee(i16 [[SPEC_SELECT]]) @@ -27,6 +30,9 @@ ; CHECK-LABEL: @test2( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[S:%.*]] = select i1 undef, i16 1, i16 0 +; CHECK-NEXT: [[TOBOOL18:%.*]] = icmp ne i16 [[S]], 0 +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[TOBOOL18]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: br label [[FOR_COND12:%.*]] ; CHECK: for.cond12: ; CHECK-NEXT: call void @callee(i16 [[S]]) @@ -53,6 +59,9 @@ ; CHECK-LABEL: @test3( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[S:%.*]] = select i1 undef, i16 1, i16 0 +; CHECK-NEXT: [[TOBOOL18:%.*]] = icmp ne i16 [[S]], 0 +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[TOBOOL18]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: br label [[FOR_COND12:%.*]] ; CHECK: for.cond12: ; CHECK-NEXT: call void @callee(i16 [[S]]) Index: llvm/trunk/test/Transforms/LoopVectorize/if-pred-stores.ll =================================================================== --- llvm/trunk/test/Transforms/LoopVectorize/if-pred-stores.ll +++ llvm/trunk/test/Transforms/LoopVectorize/if-pred-stores.ll @@ -197,6 +197,8 @@ define void @bug18724(i1 %cond) { ; UNROLL-LABEL: @bug18724( ; UNROLL-NEXT: entry: +; UNROLL-NEXT: [[TMP0:%.*]] = xor i1 [[COND:%.*]], true +; UNROLL-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; UNROLL-NEXT: br label [[FOR_BODY14:%.*]] ; UNROLL: for.body14: ; UNROLL-NEXT: [[INDVARS_IV3:%.*]] = phi i64 [ [[INDVARS_IV_NEXT4:%.*]], [[FOR_INC23:%.*]] ], [ undef, [[ENTRY:%.*]] ] @@ -211,6 +213,9 @@ ; UNROLL: for.inc23: ; UNROLL-NEXT: [[INEWCHUNKS_2]] = phi i32 [ [[INC21]], [[IF_THEN18]] ], [ [[INEWCHUNKS_120]], [[FOR_BODY14]] ] ; UNROLL-NEXT: [[INDVARS_IV_NEXT4]] = add nsw i64 [[INDVARS_IV3]], 1 +; UNROLL-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV3]] to i32 +; UNROLL-NEXT: [[CMP13:%.*]] = icmp slt i32 [[TMP1]], 0 +; UNROLL-NEXT: call void @llvm.assume(i1 [[CMP13]]) ; UNROLL-NEXT: br label [[FOR_BODY14]] ; ; UNROLL-NOSIMPLIFY-LABEL: @bug18724( @@ -287,6 +292,8 @@ ; ; VEC-LABEL: @bug18724( ; VEC-NEXT: entry: +; VEC-NEXT: [[TMP0:%.*]] = xor i1 [[COND:%.*]], true +; VEC-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; VEC-NEXT: br label [[FOR_BODY14:%.*]] ; VEC: for.body14: ; VEC-NEXT: [[INDVARS_IV3:%.*]] = phi i64 [ [[INDVARS_IV_NEXT4:%.*]], [[FOR_INC23:%.*]] ], [ undef, [[ENTRY:%.*]] ] @@ -301,6 +308,9 @@ ; VEC: for.inc23: ; VEC-NEXT: [[INEWCHUNKS_2]] = phi i32 [ [[INC21]], [[IF_THEN18]] ], [ [[INEWCHUNKS_120]], [[FOR_BODY14]] ] ; VEC-NEXT: [[INDVARS_IV_NEXT4]] = add nsw i64 [[INDVARS_IV3]], 1 +; VEC-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV3]] to i32 +; VEC-NEXT: [[CMP13:%.*]] = icmp slt i32 [[TMP1]], 0 +; VEC-NEXT: call void @llvm.assume(i1 [[CMP13]]) ; VEC-NEXT: br label [[FOR_BODY14]] ; entry: Index: llvm/trunk/test/Transforms/SimplifyCFG/PR30210.ll =================================================================== --- llvm/trunk/test/Transforms/SimplifyCFG/PR30210.ll +++ llvm/trunk/test/Transforms/SimplifyCFG/PR30210.ll @@ -10,6 +10,8 @@ ; CHECK-NEXT: entry: ; CHECK-NEXT: br label [[FOR_COND_US:%.*]] ; CHECK: for.cond.us: +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[B:%.*]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: br label [[FOR_COND_US]] ; entry: @@ -35,4 +37,4 @@ for.end: ; preds = %for.cond5 %load = load i32, i32* %call, align 4 br label %for.cond4 -} \ No newline at end of file +} Index: llvm/trunk/test/Transforms/SimplifyCFG/UnreachableEliminate.ll =================================================================== --- llvm/trunk/test/Transforms/SimplifyCFG/UnreachableEliminate.ll +++ llvm/trunk/test/Transforms/SimplifyCFG/UnreachableEliminate.ll @@ -4,6 +4,8 @@ define void @test1(i1 %C, i1* %BP) { ; CHECK-LABEL: @test1( ; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[C:%.*]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: ret void ; entry: @@ -62,6 +64,8 @@ define void @test5(i1 %cond, i8* %ptr) { ; CHECK-LABEL: @test5( ; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[COND:%.*]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: store i8 2, i8* [[PTR:%.*]], align 8 ; CHECK-NEXT: ret void ; @@ -107,6 +111,8 @@ define void @test6(i1 %cond, i8* %ptr) { ; CHECK-LABEL: @test6( ; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[COND:%.*]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: store i8 2, i8* [[PTR:%.*]], align 8 ; CHECK-NEXT: ret void ; @@ -145,6 +151,8 @@ define i32 @test7(i1 %X) { ; CHECK-LABEL: @test7( ; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: ret i32 0 ; entry: @@ -162,6 +170,8 @@ define void @test8(i1 %X, void ()* %Y) { ; CHECK-LABEL: @test8( ; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) ; CHECK-NEXT: call void [[Y:%.*]]() ; CHECK-NEXT: ret void ; @@ -196,4 +206,4 @@ ret void } -attributes #0 = { "null-pointer-is-valid"="true" } \ No newline at end of file +attributes #0 = { "null-pointer-is-valid"="true" } Index: llvm/trunk/test/Transforms/SimplifyCFG/unreachable_assume.ll =================================================================== --- llvm/trunk/test/Transforms/SimplifyCFG/unreachable_assume.ll +++ llvm/trunk/test/Transforms/SimplifyCFG/unreachable_assume.ll @@ -1,14 +1,12 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt %s -simplifycfg -instcombine -S | FileCheck %s -; TODO: ABS call should be optimized away define i32 @assume1(i32 %p) { ; CHECK-LABEL: @assume1( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[P:%.*]], 0 -; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[P]] -; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TMP0]], i32 [[NEG]], i32 [[P]] -; CHECK-NEXT: ret i32 [[TMP1]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[P:%.*]], 0 +; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) +; CHECK-NEXT: ret i32 [[P]] ; entry: %cmp = icmp sle i32 %p, 0 @@ -26,10 +24,9 @@ define i32 @assume2(i32 %p) { ; CHECK-LABEL: @assume2( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[P:%.*]], 0 -; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[P]] -; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TMP0]], i32 [[NEG]], i32 [[P]] -; CHECK-NEXT: ret i32 [[TMP1]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[P:%.*]], 0 +; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) +; CHECK-NEXT: ret i32 [[P]] ; entry: %cmp = icmp sgt i32 %p, 0