[llvm] 827fb6c - [RISCV] Add IsSignExtendingOpW to the Zknh SHA256 instructions.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 14 11:52:27 PST 2022
Author: Craig Topper
Date: 2022-12-14T11:52:01-08:00
New Revision: 827fb6c38ca59236e634f69a497a71fe94e3e99b
URL: https://github.com/llvm/llvm-project/commit/827fb6c38ca59236e634f69a497a71fe94e3e99b
DIFF: https://github.com/llvm/llvm-project/commit/827fb6c38ca59236e634f69a497a71fe94e3e99b.diff
LOG: [RISCV] Add IsSignExtendingOpW to the Zknh SHA256 instructions.
On RV64 these instructions produce a 32-bit value and sign extend
to 64-bits.
Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D140036
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfoZk.td
llvm/test/CodeGen/RISCV/sextw-removal.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td
index e4e07f4789a69..0ebe3b173ea43 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td
@@ -96,7 +96,7 @@ def AES64ES : ALU_rr<0b0011001, 0b000, "aes64es">;
def AES64ESM : ALU_rr<0b0011011, 0b000, "aes64esm">;
} // Predicates = [HasStdExtZkne, IsRV64]
-let Predicates = [HasStdExtZknh] in {
+let Predicates = [HasStdExtZknh], IsSignExtendingOpW = 1 in {
def SHA256SIG0 : RVKUnary<0b000100000010, 0b001, "sha256sig0">;
def SHA256SIG1 : RVKUnary<0b000100000011, 0b001, "sha256sig1">;
def SHA256SUM0 : RVKUnary<0b000100000000, 0b001, "sha256sum0">;
diff --git a/llvm/test/CodeGen/RISCV/sextw-removal.ll b/llvm/test/CodeGen/RISCV/sextw-removal.ll
index 23ea715a522b0..a0bb68b2ab351 100644
--- a/llvm/test/CodeGen/RISCV/sextw-removal.ll
+++ b/llvm/test/CodeGen/RISCV/sextw-removal.ll
@@ -1,9 +1,9 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+f -target-abi=lp64f \
+; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+f,+zknh -target-abi=lp64f \
; RUN: | FileCheck %s --check-prefixes=CHECK,RV64I
-; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+zbb,+f -target-abi=lp64f \
+; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+zbb,+f,+zknh -target-abi=lp64f \
; RUN: | FileCheck %s --check-prefixes=CHECK,RV64ZBB
-; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+zbb,+f -target-abi=lp64f \
+; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+zbb,+f,+zknh -target-abi=lp64f \
; RUN: -riscv-disable-sextw-removal | FileCheck %s --check-prefix=NOREMOVAL
define void @test1(i32 signext %arg, i32 signext %arg1) nounwind {
@@ -1266,3 +1266,63 @@ bb7: ; preds = %bb2
ret void
}
declare zeroext i16 @bat(i32 signext)
+
+define void @test18(i32 signext %arg, i32 signext %arg1) nounwind {
+; CHECK-LABEL: test18:
+; CHECK: # %bb.0: # %bb
+; CHECK-NEXT: addi sp, sp, -32
+; CHECK-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd s0, 16(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd s1, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT: mv s0, a1
+; CHECK-NEXT: sha256sig0 s1, a1
+; CHECK-NEXT: .LBB21_1: # %bb2
+; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
+; CHECK-NEXT: mv a0, s1
+; CHECK-NEXT: call bar at plt
+; CHECK-NEXT: sllw s1, s1, s0
+; CHECK-NEXT: bnez a0, .LBB21_1
+; CHECK-NEXT: # %bb.2: # %bb7
+; CHECK-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld s0, 16(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld s1, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT: addi sp, sp, 32
+; CHECK-NEXT: ret
+;
+; NOREMOVAL-LABEL: test18:
+; NOREMOVAL: # %bb.0: # %bb
+; NOREMOVAL-NEXT: addi sp, sp, -32
+; NOREMOVAL-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
+; NOREMOVAL-NEXT: sd s0, 16(sp) # 8-byte Folded Spill
+; NOREMOVAL-NEXT: sd s1, 8(sp) # 8-byte Folded Spill
+; NOREMOVAL-NEXT: mv s0, a1
+; NOREMOVAL-NEXT: sha256sig0 s1, a1
+; NOREMOVAL-NEXT: .LBB21_1: # %bb2
+; NOREMOVAL-NEXT: # =>This Inner Loop Header: Depth=1
+; NOREMOVAL-NEXT: sext.w a0, s1
+; NOREMOVAL-NEXT: call bar at plt
+; NOREMOVAL-NEXT: sllw s1, s1, s0
+; NOREMOVAL-NEXT: bnez a0, .LBB21_1
+; NOREMOVAL-NEXT: # %bb.2: # %bb7
+; NOREMOVAL-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
+; NOREMOVAL-NEXT: ld s0, 16(sp) # 8-byte Folded Reload
+; NOREMOVAL-NEXT: ld s1, 8(sp) # 8-byte Folded Reload
+; NOREMOVAL-NEXT: addi sp, sp, 32
+; NOREMOVAL-NEXT: ret
+bb:
+ %sext = sext i32 %arg1 to i64
+ %i = call i64 @llvm.riscv.sha256sig0.i64(i64 %sext)
+ %trunc = trunc i64 %i to i32
+ br label %bb2
+
+bb2: ; preds = %bb2, %bb
+ %i3 = phi i32 [ %trunc, %bb ], [ %i5, %bb2 ]
+ %i4 = tail call signext i32 @bar(i32 signext %i3)
+ %i5 = shl i32 %i3, %arg1
+ %i6 = icmp eq i32 %i4, 0
+ br i1 %i6, label %bb7, label %bb2
+
+bb7: ; preds = %bb2
+ ret void
+}
+declare i64 @llvm.riscv.sha256sig0.i64(i64)
More information about the llvm-commits
mailing list