diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-06-25 18:51:21 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-06-25 18:51:21 +0000 |
commit | 1e911fa746ab00b50a70756288455ee8499aadf0 (patch) | |
tree | b5536f376e4a30ec782d2f699e6b4976b5b98f86 /llvm/lib | |
parent | a8448ad09823e3ea38dc4a50e815ebd46cdc2cd9 (diff) | |
download | bcm5719-llvm-1e911fa746ab00b50a70756288455ee8499aadf0.tar.gz bcm5719-llvm-1e911fa746ab00b50a70756288455ee8499aadf0.zip |
[InstSimplify] fold div/rem of zexted bool
I was looking at an unrelated fold and noticed that
we don't have this simplification (because the other
fold would break existing tests).
Name: zext udiv
%z = zext i1 %x to i32
%r = udiv i32 %y, %z
=>
%r = %y
Name: zext urem
%z = zext i1 %x to i32
%r = urem i32 %y, %z
=>
%r = 0
Name: zext sdiv
%z = zext i1 %x to i32
%r = sdiv i32 %y, %z
=>
%r = %y
Name: zext srem
%z = zext i1 %x to i32
%r = srem i32 %y, %z
=>
%r = 0
https://rise4fun.com/Alive/LZ9
llvm-svn: 335512
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index f1bfa33276b..4f5bed91dcc 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -902,7 +902,10 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv) { // X % 1 -> 0 // If this is a boolean op (single-bit element type), we can't have // division-by-zero or remainder-by-zero, so assume the divisor is 1. - if (match(Op1, m_One()) || Ty->isIntOrIntVectorTy(1)) + // Similarly, if we're zero-extending a boolean divisor, then assume it's a 1. + Value *X; + if (match(Op1, m_One()) || Ty->isIntOrIntVectorTy(1) || + (match(Op1, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1))) return IsDiv ? Op0 : Constant::getNullValue(Ty); return nullptr; |