diff options
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 2 | ||||
-rw-r--r-- | llvm/test/Transforms/InstSimplify/undef.ll | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 00ff9788a9c..aea8308e9c6 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -948,7 +948,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, case Instruction::SDiv: case Instruction::UDiv: // X / undef -> undef - if (match(C1, m_Zero())) + if (isa<UndefValue>(C2)) return C2; // undef / 0 -> undef // undef / 1 -> undef diff --git a/llvm/test/Transforms/InstSimplify/undef.ll b/llvm/test/Transforms/InstSimplify/undef.ll index d75dc364243..6141180e08d 100644 --- a/llvm/test/Transforms/InstSimplify/undef.ll +++ b/llvm/test/Transforms/InstSimplify/undef.ll @@ -279,3 +279,24 @@ define i32 @test36(i32 %V) { %b = extractelement <4 x i32> undef, i32 %V ret i32 %b } + +; CHECK-LABEL: @test37 +; CHECK: ret i32 undef +define i32 @test37() { + %b = udiv i32 undef, undef + ret i32 %b +} + +; CHECK-LABEL: @test38 +; CHECK: ret i32 undef +define i32 @test38(i32 %a) { + %b = udiv i32 %a, undef + ret i32 %b +} + +; CHECK-LABEL: @test39 +; CHECK: ret i32 undef +define i32 @test39() { + %b = udiv i32 0, undef + ret i32 %b +} |