Skip to content

Instantly share code, notes, and snippets.

@nikic

nikic/.diff Secret

Created Sep 12, 2020
Embed
What would you like to do?
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 56c47f84bae..cd91e8ade98 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1067,7 +1067,7 @@ static Instruction *canonicalizeMinMaxWithConstant(SelectInst &Sel,
/// Canonicalize select-based abs/nabs to llvm.abs() intrinsic.
static Instruction *canonicalizeAbsNabs(SelectInst &Sel, ICmpInst &Cmp,
InstCombinerImpl &IC) {
- if (!Cmp.hasOneUse() || !isa<Constant>(Cmp.getOperand(1)))
+ if (!isa<Constant>(Cmp.getOperand(1)))
return nullptr;
Value *LHS, *RHS;
diff --git a/llvm/test/Transforms/InstCombine/abs-1.ll b/llvm/test/Transforms/InstCombine/abs-1.ll
index fbc0fc1a835..cc3bb510ee8 100644
--- a/llvm/test/Transforms/InstCombine/abs-1.ll
+++ b/llvm/test/Transforms/InstCombine/abs-1.ll
@@ -594,9 +594,8 @@ define i8 @abs_extra_use_icmp(i8 %x) {
; CHECK-LABEL: @abs_extra_use_icmp(
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
-; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
-; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[N]], i8 [[X]]
-; CHECK-NEXT: ret i8 [[S]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.abs.i8(i8 [[X]], i1 false)
+; CHECK-NEXT: ret i8 [[TMP1]]
;
%c = icmp slt i8 %x, 0
call void @extra_use_i1(i1 %c)
@@ -625,8 +624,8 @@ define i8 @abs_extra_use_icmp_sub(i8 %x) {
; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
; CHECK-NEXT: call void @extra_use(i8 [[N]])
-; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[N]], i8 [[X]]
-; CHECK-NEXT: ret i8 [[S]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.abs.i8(i8 [[X]], i1 false)
+; CHECK-NEXT: ret i8 [[TMP1]]
;
%c = icmp slt i8 %x, 0
call void @extra_use_i1(i1 %c)
@@ -640,8 +639,8 @@ define i8 @nabs_extra_use_icmp(i8 %x) {
; CHECK-LABEL: @nabs_extra_use_icmp(
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
-; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
-; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.abs.i8(i8 [[X]], i1 false)
+; CHECK-NEXT: [[S:%.*]] = sub i8 0, [[TMP1]]
; CHECK-NEXT: ret i8 [[S]]
;
%c = icmp slt i8 %x, 0
@@ -672,7 +671,8 @@ define i8 @nabs_extra_use_icmp_sub(i8 %x) {
; CHECK-NEXT: call void @extra_use_i1(i1 [[C]])
; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X]]
; CHECK-NEXT: call void @extra_use(i8 [[N]])
-; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.abs.i8(i8 [[X]], i1 false)
+; CHECK-NEXT: [[S:%.*]] = sub i8 0, [[TMP1]]
; CHECK-NEXT: ret i8 [[S]]
;
%c = icmp slt i8 %x, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment