[llvm] r336679 - [InstCombine] drop poison flags when shuffle mask undef propagates to constant
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 10 07:27:55 PDT 2018
Author: spatel
Date: Tue Jul 10 07:27:55 2018
New Revision: 336679
URL: http://llvm.org/viewvc/llvm-project?rev=336679&view=rev
Log:
[InstCombine] drop poison flags when shuffle mask undef propagates to constant
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/trunk/test/Transforms/InstCombine/shuffle_select.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=336679&r1=336678&r2=336679&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Tue Jul 10 07:27:55 2018
@@ -1223,6 +1223,11 @@ static Instruction *foldSelectShuffleWit
// shuf X, (bop X, C), M --> bop X, C'
Instruction *NewBO = BinaryOperator::Create(BOpcode, X, NewC);
NewBO->copyIRFlags(BO);
+
+ // An undef shuffle mask element may propagate as an undef constant element in
+ // the new binop. That would produce poison where the original code might not.
+ if (Mask->containsUndefElement())
+ NewBO->dropPoisonGeneratingFlags();
return NewBO;
}
Modified: llvm/trunk/test/Transforms/InstCombine/shuffle_select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shuffle_select.ll?rev=336679&r1=336678&r2=336679&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/shuffle_select.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/shuffle_select.ll Tue Jul 10 07:27:55 2018
@@ -36,11 +36,11 @@ define <4 x i32> @add_undef_mask_elt(<4
ret <4 x i32> %s
}
-; FIXME: Poison flags must be dropped or undef must be replaced with safe constant.
+; Poison flags must be dropped or undef must be replaced with safe constant.
define <4 x i32> @add_nuw_nsw_undef_mask_elt(<4 x i32> %v) {
; CHECK-LABEL: @add_nuw_nsw_undef_mask_elt(
-; CHECK-NEXT: [[S:%.*]] = add nuw nsw <4 x i32> [[V:%.*]], <i32 11, i32 undef, i32 13, i32 0>
+; CHECK-NEXT: [[S:%.*]] = add <4 x i32> [[V:%.*]], <i32 11, i32 undef, i32 13, i32 0>
; CHECK-NEXT: ret <4 x i32> [[S]]
;
%b = add nuw nsw <4 x i32> %v, <i32 11, i32 12, i32 13, i32 14>
@@ -63,12 +63,11 @@ define <4 x i32> @sub(<4 x i32> %v) {
; If any element of the shuffle mask operand is undef, that element of the result is undef.
; The shuffle is eliminated in this transform, but we can replace a constant element with undef.
-; FIXME:
; Preserve flags when possible. It's not safe to propagate poison-generating flags with undef constants.
define <4 x i32> @mul(<4 x i32> %v) {
; CHECK-LABEL: @mul(
-; CHECK-NEXT: [[S:%.*]] = mul nuw nsw <4 x i32> [[V:%.*]], <i32 undef, i32 12, i32 1, i32 14>
+; CHECK-NEXT: [[S:%.*]] = mul <4 x i32> [[V:%.*]], <i32 undef, i32 12, i32 1, i32 14>
; CHECK-NEXT: ret <4 x i32> [[S]]
;
%b = mul nsw nuw <4 x i32> %v, <i32 11, i32 12, i32 13, i32 14>
More information about the llvm-commits
mailing list