Index: llvm/test/Transforms/InstCombine/add.ll =================================================================== --- llvm/test/Transforms/InstCombine/add.ll +++ llvm/test/Transforms/InstCombine/add.ll @@ -357,6 +357,28 @@ ret i8 %C } +; ~X + -127 and (-128) - X with nsw are equally poisonous +define i8 @test18_nsw(i8 %A) { +; CHECK-LABEL: @test18_nsw( +; CHECK-NEXT: [[C:%.*]] = sub i8 -128, [[A:%.*]] +; CHECK-NEXT: ret i8 [[C]] +; + %B = xor i8 %A, -1 + %C = add nsw i8 %B, -127 + ret i8 %C +} + +; 127 - X with nsw will be more poisonous than ~X + -128 with nsw. (see X = -1) +define i8 @test18_nsw_overflow(i8 %A) { +; CHECK-LABEL: @test18_nsw_overflow( +; CHECK-NEXT: [[C:%.*]] = sub i8 127, [[A:%.*]] +; CHECK-NEXT: ret i8 [[C]] +; + %B = xor i8 %A, -1 + %C = add nsw i8 %B, -128 + ret i8 %C +} + define <2 x i64> @test18vec(<2 x i64> %A) { ; CHECK-LABEL: @test18vec( ; CHECK-NEXT: [[ADD:%.*]] = sub <2 x i64> , [[A:%.*]]