Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -37,7 +37,7 @@ if (BinaryOperator *I = dyn_cast(Val)) { // Cannot look past anything that might overflow. OverflowingBinaryOperator *OBI = dyn_cast(Val); - if (OBI && !OBI->hasNoUnsignedWrap() && !OBI->hasNoSignedWrap()) { + if (OBI && !OBI->hasNoUnsignedWrap()) { Scale = 1; Offset = 0; return Val; Index: llvm/test/Transforms/InstCombine/neg-alloca.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/InstCombine/neg-alloca.ll @@ -0,0 +1,29 @@ +; RUN: opt -S -passes=instcombine < %s | FileCheck %s +@test = external global [1 x i32], align 16 + +define void @foo() { + br label %b0 + +b0: + %1 = phi i64 [ 1, %0 ], [ %9, %b0 ] +; Currently we cannot handle expressions of the form Offset - X * Scale. +; CHECK: mul nsw i64 %1, -4 +; CHECK: alloca i8 + %2 = mul nsw i64 %1, -4 + %3 = add nsw i64 %2, 24 + %4 = alloca i8, i64 %3, align 4 + %5 = bitcast i8* %4 to i32* + store i32 undef, i32* %5, align 4 + + %6 = load i8, i8* %4, align 4 + %7 = getelementptr inbounds [1 x i32], [1 x i32]* @test, i64 0, i8 %6 + %8 = load i32, i32* %7, align 4 + store i32 %8, i32* undef, align 4 + + %9 = add nuw nsw i64 %1, 1 + br i1 undef, label %bend, label %b0 + +bend: + ret void +} +