Skip to content

Commit

Permalink
Merged master:6a44edb8da33 into amd-gfx:b3b0d224fe25
Browse files Browse the repository at this point in the history
Local branch amd-gfx b3b0d22 Merged master:3d1b0000f9da into amd-gfx:705782cee308
Remote branch master 6a44edb [InstCombine] fold abs of select with negated op (PR39474)
  • Loading branch information
Sw authored and Sw committed Aug 24, 2020
2 parents b3b0d22 + 6a44edb commit 568c74a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Type;
assert(i == 0 && "Operand index out of range!");
return Operands[0];
}
using op_iterator = const SCEV *const *;
using op_iterator = std::array<const SCEV *, 1>::const_iterator;
using op_range = iterator_range<op_iterator>;

op_range operands() const {
Expand Down Expand Up @@ -274,7 +274,7 @@ class Type;
class SCEVUDivExpr : public SCEV {
friend class ScalarEvolution;

std::array<const SCEV*, 2> Operands;
std::array<const SCEV *, 2> Operands;

SCEVUDivExpr(const FoldingSetNodeIDRef ID, const SCEV *lhs, const SCEV *rhs)
: SCEV(ID, scUDivExpr, computeExpressionSize({lhs, rhs})) {
Expand All @@ -291,7 +291,7 @@ class Type;
return i == 0 ? getLHS() : getRHS();
}

using op_iterator = const SCEV *const *;
using op_iterator = std::array<const SCEV *, 2>::const_iterator;
using op_range = iterator_range<op_iterator>;
op_range operands() const {
return make_range(Operands.begin(), Operands.end());
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
Value *X;
if (match(IIOperand, m_Neg(m_Value(X))))
return replaceOperand(*II, 0, X);
if (match(IIOperand, m_Select(m_Value(), m_Value(X), m_Neg(m_Deferred(X)))))
return replaceOperand(*II, 0, X);
if (match(IIOperand, m_Select(m_Value(), m_Neg(m_Value(X)), m_Deferred(X))))
return replaceOperand(*II, 0, X);

break;
}
Expand Down
22 changes: 22 additions & 0 deletions llvm/test/Transforms/InstCombine/abs-intrinsic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,25 @@ define <4 x i32> @abs_of_neg_vec(<4 x i32> %x) {
%b = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %a, i1 false)
ret <4 x i32> %b
}

define i32 @abs_of_select_neg_true_val(i1 %b, i32 %x) {
; CHECK-LABEL: @abs_of_select_neg_true_val(
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
; CHECK-NEXT: ret i32 [[ABS]]
;
%neg = sub i32 0, %x
%sel = select i1 %b, i32 %neg, i32 %x
%abs = call i32 @llvm.abs.i32(i32 %sel, i1 true)
ret i32 %abs
}

define <4 x i32> @abs_of_select_neg_false_val(<4 x i1> %b, <4 x i32> %x) {
; CHECK-LABEL: @abs_of_select_neg_false_val(
; CHECK-NEXT: [[ABS:%.*]] = call <4 x i32> @llvm.abs.v4i32(<4 x i32> [[X:%.*]], i1 false)
; CHECK-NEXT: ret <4 x i32> [[ABS]]
;
%neg = sub <4 x i32> zeroinitializer, %x
%sel = select <4 x i1> %b, <4 x i32> %x, <4 x i32> %neg
%abs = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %sel, i1 false)
ret <4 x i32> %abs
}

0 comments on commit 568c74a

Please sign in to comment.