Skip to content

Commit e931708

Browse files
committed
Fold RISCV sign extension operations is their result will compared with zero.
sext_ext(0) == 0.
1 parent cce371d commit e931708

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17201,6 +17201,12 @@ static bool combine_CC(SDValue &LHS, SDValue &RHS, SDValue &CC, const SDLoc &DL,
1720117201
return true;
1720217202
}
1720317203

17204+
// Fold ((sext X), 0, eq/ne) -> (X, 0, eq/ne)
17205+
if (LHS.getOpcode() == ISD::SIGN_EXTEND_INREG && isNullConstant(RHS)) {
17206+
LHS = LHS.getOperand(0);
17207+
return true;
17208+
}
17209+
1720417210
// Fold ((srl (and X, 1<<C), C), 0, eq/ne) -> ((shl X, XLen-1-C), 0, ge/lt)
1720517211
if (isNullConstant(RHS) && LHS.getOpcode() == ISD::SRL && LHS.hasOneUse() &&
1720617212
LHS.getOperand(1).getOpcode() == ISD::Constant) {

llvm/test/CodeGen/RISCV/select-constant-xor.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ define i32 @branch_sext_ret(i32 %x) {
255255
;
256256
; RV64-LABEL: branch_sext_ret:
257257
; RV64: # %bb.0: # %entry
258-
; RV64-NEXT: sext.w a1, a0
259-
; RV64-NEXT: beqz a1, .LBB11_2
258+
; RV64-NEXT: beqz a0, .LBB11_2
260259
; RV64-NEXT: # %bb.1: # %if.then
261260
; RV64-NEXT: ret
262261
; RV64-NEXT: .LBB11_2: # %if.end

0 commit comments

Comments
 (0)