Skip to content

Commit c181e45

Browse files
[EVM][DAGCombine] Implement TLI hooks related to select
These hooks will reduce number of select instructions. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent a424406 commit c181e45

File tree

4 files changed

+75
-291
lines changed

4 files changed

+75
-291
lines changed

llvm/lib/Target/EVM/EVMISelLowering.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ class EVMTargetLowering final : public TargetLowering {
115115
return false;
116116
}
117117

118+
/// Returns true if we should normalize
119+
/// select(N0&N1, X, Y) => select(N0, select(N1, X, Y), Y) and
120+
/// select(N0|N1, X, Y) => select(N0, select(N1, X, Y, Y)) if it is likely
121+
/// that it saves us from materializing N0 and N1 in an integer register.
122+
/// For EVM, selects are expensive, so generating more selects is not
123+
/// beneficial.
124+
bool shouldNormalizeToSelectSequence(LLVMContext &Context,
125+
EVT VT) const override {
126+
return false;
127+
}
128+
129+
/// Return true if a select of constants (select Cond, C1, C2) should be
130+
/// transformed into simple math ops with the condition value. For example:
131+
/// select Cond, C1, C1-1 --> add (zext Cond), C1-1
132+
/// For EVM, selects are expensive, so reducing number of selects is
133+
/// beneficial.
134+
bool convertSelectOfConstantsToMath(EVT VT) const override { return true; }
135+
118136
private:
119137
const EVMSubtarget *Subtarget;
120138

llvm/test/CodeGen/EVM/dont-avoid-shift-transformations.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ define i256 @test7(i256 %x) {
119119
; CHECK-LABEL: test7:
120120
; CHECK: ; %bb.0: ; %entry
121121
; CHECK-NEXT: JUMPDEST
122-
; CHECK-NEXT: PUSH1 0x2
123-
; CHECK-NEXT: SWAP1
124-
; CHECK-NEXT: PUSH1 0xFE
122+
; CHECK-NEXT: PUSH1 0xFF
125123
; CHECK-NEXT: SHR
126-
; CHECK-NEXT: AND
124+
; CHECK-NEXT: PUSH1 0x1
125+
; CHECK-NEXT: SHL
127126
; CHECK-NEXT: SWAP1
128127
; CHECK-NEXT: JUMP
129128
entry:

0 commit comments

Comments
 (0)