Skip to content

Commit 3c20ede

Browse files
committed
[InstSimplify] fold integer min/max intrinsic with same args
1 parent a4ade9e commit 3c20ede

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5258,6 +5258,10 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
52585258
case Intrinsic::smin:
52595259
case Intrinsic::umax:
52605260
case Intrinsic::umin: {
5261+
// If the arguments are the same, this is a no-op.
5262+
if (Op0 == Op1)
5263+
return Op0;
5264+
52615265
// Canonicalize constant operand as Op1.
52625266
if (isa<Constant>(Op0))
52635267
std::swap(Op0, Op1);

llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,31 @@ declare <2 x i8> @llvm.umin.v2i8(<2 x i8>, <2 x i8>)
1414

1515
define i81 @smax_sameval(i81 %x) {
1616
; CHECK-LABEL: @smax_sameval(
17-
; CHECK-NEXT: [[R:%.*]] = call i81 @llvm.smax.i81(i81 [[X:%.*]], i81 [[X]])
18-
; CHECK-NEXT: ret i81 [[R]]
17+
; CHECK-NEXT: ret i81 [[X:%.*]]
1918
;
2019
%r = call i81 @llvm.smax.i81(i81 %x, i81 %x)
2120
ret i81 %r
2221
}
2322

2423
define i3 @smin_sameval(i3 %x) {
2524
; CHECK-LABEL: @smin_sameval(
26-
; CHECK-NEXT: [[R:%.*]] = call i3 @llvm.smin.i3(i3 [[X:%.*]], i3 [[X]])
27-
; CHECK-NEXT: ret i3 [[R]]
25+
; CHECK-NEXT: ret i3 [[X:%.*]]
2826
;
2927
%r = call i3 @llvm.smin.i3(i3 %x, i3 %x)
3028
ret i3 %r
3129
}
3230

3331
define <2 x i8> @umax_sameval(<2 x i8> %x) {
3432
; CHECK-LABEL: @umax_sameval(
35-
; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.umax.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[X]])
36-
; CHECK-NEXT: ret <2 x i8> [[R]]
33+
; CHECK-NEXT: ret <2 x i8> [[X:%.*]]
3734
;
3835
%r = call <2 x i8> @llvm.umax.v2i8(<2 x i8> %x, <2 x i8> %x)
3936
ret <2 x i8> %r
4037
}
4138

4239
define <2 x i8> @umin_sameval(<2 x i8> %x) {
4340
; CHECK-LABEL: @umin_sameval(
44-
; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.umin.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[X]])
45-
; CHECK-NEXT: ret <2 x i8> [[R]]
41+
; CHECK-NEXT: ret <2 x i8> [[X:%.*]]
4642
;
4743
%r = call <2 x i8> @llvm.umin.v2i8(<2 x i8> %x, <2 x i8> %x)
4844
ret <2 x i8> %r

0 commit comments

Comments
 (0)