[PATCH] D42341: [LLVM][PASSES][InstSimplify] Add (X << Y) % X -> 0
Anton Bikineev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 21 07:48:19 PST 2018
AntonBikineev updated this revision to Diff 130809.
https://reviews.llvm.org/D42341
Files:
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/rem.ll
Index: test/Transforms/InstSimplify/rem.ll
===================================================================
--- test/Transforms/InstSimplify/rem.ll
+++ test/Transforms/InstSimplify/rem.ll
@@ -189,20 +189,16 @@
define i32 @rem5(i32 %x, i32 %y) {
; CHECK-LABEL: @rem5(
-; CHECK-NEXT: [[SHL:%.*]] = shl nsw i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[MOD:%.*]] = srem i32 [[SHL]], [[X]]
-; CHECK-NEXT: ret i32 [[MOD]]
+; CHECK-NEXT: ret i32 0
;
%shl = shl nsw i32 %x, %y
%mod = srem i32 %shl, %x
ret i32 %mod
}
define <2 x i32> @rem6(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @rem6(
-; CHECK-NEXT: [[SHL:%.*]] = shl nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[MOD:%.*]] = srem <2 x i32> [[SHL]], [[X]]
-; CHECK-NEXT: ret <2 x i32> [[MOD]]
+; CHECK-NEXT: ret <2 x i32> zeroinitializer
;
%shl = shl nsw <2 x i32> %x, %y
%mod = srem <2 x i32> %shl, %x
@@ -224,20 +220,16 @@
define i32 @rem8(i32 %x, i32 %y) {
; CHECK-LABEL: @rem8(
-; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[MOD:%.*]] = urem i32 [[SHL]], [[X]]
-; CHECK-NEXT: ret i32 [[MOD]]
+; CHECK-NEXT: ret i32 0
;
%shl = shl nuw i32 %x, %y
%mod = urem i32 %shl, %x
ret i32 %mod
}
define <2 x i32> @rem9(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @rem9(
-; CHECK-NEXT: [[SHL:%.*]] = shl nuw <2 x i32> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[MOD:%.*]] = urem <2 x i32> [[SHL]], [[X]]
-; CHECK-NEXT: ret <2 x i32> [[MOD]]
+; CHECK-NEXT: ret <2 x i32> zeroinitializer
;
%shl = shl nuw <2 x i32> %x, %y
%mod = urem <2 x i32> %shl, %x
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -1040,6 +1040,13 @@
match(Op0, m_URem(m_Value(), m_Specific(Op1)))))
return Op0;
+ // (X << Y) % X -> 0
+ if ((Opcode == Instruction::SRem &&
+ match(Op0, m_NSWShl(m_Specific(Op1), m_Value()))) ||
+ (Opcode == Instruction::URem &&
+ match(Op0, m_NUWShl(m_Specific(Op1), m_Value()))))
+ return Constant::getNullValue(Op0->getType());
+
// If the operation is with the result of a select instruction, check whether
// operating on either branch of the select always yields the same value.
if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42341.130809.patch
Type: text/x-patch
Size: 2405 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180121/067e4cd9/attachment.bin>
More information about the llvm-commits
mailing list