[llvm] r335633 - [InstSimplify] fold shifts by sext bool
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 26 10:31:38 PDT 2018
Author: spatel
Date: Tue Jun 26 10:31:38 2018
New Revision: 335633
URL: http://llvm.org/viewvc/llvm-project?rev=335633&view=rev
Log:
[InstSimplify] fold shifts by sext bool
https://rise4fun.com/Alive/c3Y
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/shift.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=335633&r1=335632&r2=335633&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Jun 26 10:31:38 2018
@@ -1162,7 +1162,11 @@ static Value *SimplifyShift(Instruction:
return Constant::getNullValue(Op0->getType());
// X shift by 0 -> X
- if (match(Op1, m_Zero()))
+ // Shift-by-sign-extended bool must be shift-by-0 because shift-by-all-ones
+ // would be poison.
+ Value *X;
+ if (match(Op1, m_Zero()) ||
+ (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)))
return Op0;
// Fold undefined shifts.
Modified: llvm/trunk/test/Transforms/InstSimplify/shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/shift.ll?rev=335633&r1=335632&r2=335633&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/shift.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/shift.ll Tue Jun 26 10:31:38 2018
@@ -123,9 +123,7 @@ define <3 x i8> @ashr_all_ones_vec_with_
define i8 @lshr_by_sext_bool(i1 %x, i8 %y) {
; CHECK-LABEL: @lshr_by_sext_bool(
-; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i8
-; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], [[S]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 [[Y:%.*]]
;
%s = sext i1 %x to i8
%r = lshr i8 %y, %s
@@ -134,9 +132,7 @@ define i8 @lshr_by_sext_bool(i1 %x, i8 %
define <2 x i8> @lshr_by_sext_bool_vec(<2 x i1> %x, <2 x i8> %y) {
; CHECK-LABEL: @lshr_by_sext_bool_vec(
-; CHECK-NEXT: [[S:%.*]] = sext <2 x i1> [[X:%.*]] to <2 x i8>
-; CHECK-NEXT: [[R:%.*]] = lshr <2 x i8> [[Y:%.*]], [[S]]
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: ret <2 x i8> [[Y:%.*]]
;
%s = sext <2 x i1> %x to <2 x i8>
%r = lshr <2 x i8> %y, %s
@@ -145,9 +141,7 @@ define <2 x i8> @lshr_by_sext_bool_vec(<
define i8 @ashr_by_sext_bool(i1 %x, i8 %y) {
; CHECK-LABEL: @ashr_by_sext_bool(
-; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i8
-; CHECK-NEXT: [[R:%.*]] = ashr i8 [[Y:%.*]], [[S]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 [[Y:%.*]]
;
%s = sext i1 %x to i8
%r = ashr i8 %y, %s
@@ -156,9 +150,7 @@ define i8 @ashr_by_sext_bool(i1 %x, i8 %
define <2 x i8> @ashr_by_sext_bool_vec(<2 x i1> %x, <2 x i8> %y) {
; CHECK-LABEL: @ashr_by_sext_bool_vec(
-; CHECK-NEXT: [[S:%.*]] = sext <2 x i1> [[X:%.*]] to <2 x i8>
-; CHECK-NEXT: [[R:%.*]] = ashr <2 x i8> [[Y:%.*]], [[S]]
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: ret <2 x i8> [[Y:%.*]]
;
%s = sext <2 x i1> %x to <2 x i8>
%r = ashr <2 x i8> %y, %s
@@ -167,9 +159,7 @@ define <2 x i8> @ashr_by_sext_bool_vec(<
define i8 @shl_by_sext_bool(i1 %x, i8 %y) {
; CHECK-LABEL: @shl_by_sext_bool(
-; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i8
-; CHECK-NEXT: [[R:%.*]] = shl i8 [[Y:%.*]], [[S]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 [[Y:%.*]]
;
%s = sext i1 %x to i8
%r = shl i8 %y, %s
@@ -178,9 +168,7 @@ define i8 @shl_by_sext_bool(i1 %x, i8 %y
define <2 x i8> @shl_by_sext_bool_vec(<2 x i1> %x, <2 x i8> %y) {
; CHECK-LABEL: @shl_by_sext_bool_vec(
-; CHECK-NEXT: [[S:%.*]] = sext <2 x i1> [[X:%.*]] to <2 x i8>
-; CHECK-NEXT: [[R:%.*]] = shl <2 x i8> [[Y:%.*]], [[S]]
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: ret <2 x i8> [[Y:%.*]]
;
%s = sext <2 x i1> %x to <2 x i8>
%r = shl <2 x i8> %y, %s
More information about the llvm-commits
mailing list