Skip to content

Commit

Permalink
[InstCombine] Fix Incorrect fold of ashr+xor -> lshr w/ vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jroelofs committed Mar 26, 2020
1 parent fe025a3 commit 7a89a5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Expand Up @@ -3069,8 +3069,12 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
// ~(C >>s Y) --> ~C >>u Y (when inverting the replicated sign bits)
Constant *C;
if (match(NotVal, m_AShr(m_Constant(C), m_Value(Y))) &&
match(C, m_Negative()))
return BinaryOperator::CreateLShr(ConstantExpr::getNot(C), Y);
match(C, m_Negative())) {
Constant *NewC = ConstantExpr::getNot(C);
if (C->getType()->isVectorTy())
NewC = getSafeVectorConstantForBinop(Instruction::LShr, NewC, false);
return BinaryOperator::CreateLShr(NewC, Y);
}

// ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits)
if (match(NotVal, m_LShr(m_Constant(C), m_Value(Y))) &&
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/InstCombine/vector-xor.ll
Expand Up @@ -140,7 +140,7 @@ define <4 x i32> @test_v4i32_not_ashr_negative_const(<4 x i32> %a0) {

define <4 x i32> @test_v4i32_not_ashr_negative_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_ashr_negative_const_undef(
; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 4, i32 undef, i32 8>, [[A0:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 4, i32 0, i32 8>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = ashr <4 x i32> <i32 -3, i32 -5, i32 undef, i32 -9>, %a0
Expand Down

0 comments on commit 7a89a5d

Please sign in to comment.