[llvm] r223919 - InstSimplify: div %X, 0 -> undef
David Majnemer
david.majnemer at gmail.com
Tue Dec 9 23:52:19 PST 2014
Author: majnemer
Date: Wed Dec 10 01:52:18 2014
New Revision: 223919
URL: http://llvm.org/viewvc/llvm-project?rev=223919&view=rev
Log:
InstSimplify: div %X, 0 -> undef
We already optimized rem %X, 0 to undef, we should do the same for div.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/undef.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=223919&r1=223918&r2=223919&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Dec 10 01:52:18 2014
@@ -1011,6 +1011,10 @@ static Value *SimplifyDiv(Instruction::B
if (match(Op1, m_Undef()))
return Op1;
+ // X / 0 -> undef, we don't need to preserve faults!
+ if (match(Op1, m_Zero()))
+ return UndefValue::get(Op1->getType());
+
// undef / X -> 0
if (match(Op0, m_Undef()))
return Constant::getNullValue(Op0->getType());
Modified: llvm/trunk/test/Transforms/InstSimplify/undef.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/undef.ll?rev=223919&r1=223918&r2=223919&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/undef.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/undef.ll Wed Dec 10 01:52:18 2014
@@ -160,3 +160,17 @@ define <4 x i8> @test19(<4 x i8> %a) {
%b = shl <4 x i8> %a, <i8 8, i8 9, i8 undef, i8 -1>
ret <4 x i8> %b
}
+
+; CHECK-LABEL: @test20
+; CHECK: ret i32 undef
+define i32 @test20(i32 %a) {
+ %b = udiv i32 %a, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test21
+; CHECK: ret i32 undef
+define i32 @test21(i32 %a) {
+ %b = sdiv i32 %a, 0
+ ret i32 %b
+}
More information about the llvm-commits
mailing list