Where C is a simm32.
This costs an extra temporary register, but avoids a constant pool.
Paths
| Differential D152236
[RISCV] Add special case to selectImm for constants that can be created with (ADD (SLLI C, 32), C). ClosedPublic Authored by craig.topper on Jun 5 2023, 11:51 PM.
Details Summary Where C is a simm32. This costs an extra temporary register, but avoids a constant pool.
Diff Detail
Event TimelineComment Actions I'd not really explored such materialisations before as adding another dimension to cost modeling (register usage) felt difficult to reason about...but intuitively I can't see spending an extra register being problematic in this specific case where a constant pool would have been used, and given how relatively register rich RISC-V is. I am however seeing some compile failures for this e.g. 20000523-1.c from the GCC torture suite (e.g. compiled rv64imafdc for lp64 ABI at O0) /home/asb/llvm-project/llvm/lib/MC/MCInst.cpp:58: bool llvm::MCOperand::isBareSymbolRef() const: Assertion `isExpr() && "isBareSymbolRef expects only expressions"' failed. ... Comment Actions General approach seems entirely reasonable to me.
This revision is now accepted and ready to land.Jun 6 2023, 11:44 AM This revision was landed with ongoing or failed builds.Jun 6 2023, 11:59 AM Closed by commit rG58b2d652af49: [RISCV] Add special case to selectImm for constants that can be created with… (authored by craig.topper). · Explain Why This revision was automatically updated to reflect the committed changes. Comment Actions I think this broke sanitizer tests: https://lab.llvm.org/buildbot/#/builders/238/builds/3867/steps/13/logs/stdio Comment Actions /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:214:43: runtime error: signed integer overflow: 9223372034904144827 - -1950630981 cannot be represented in type 'int64_t' (aka 'long') #0 0xaaaae4525208 in selectImm(llvm::SelectionDAG*, llvm::SDLoc const&, llvm::MVT, long, llvm::RISCVSubtarget const&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:214:43 #1 0xaaaae451fff8 in llvm::RISCVDAGToDAGISel::Select(llvm::SDNode*) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:863:23 #2 0xaaaae6204148 in llvm::SelectionDAGISel::DoInstructionSelection() /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1178:7 #3 0xaaaae6202418 in llvm::SelectionDAGISel::CodeGenAndEmitDAG() /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:949:5 #4 0xaaaae61feb54 in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1700:7 #5 0xaaaae61fa77c in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:482:3 #6 0xaaaae5469750 in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:91:13 #7 0xaaaae5b2acf0 in llvm::FPPassManager::runOnFunction(llvm::Function&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1435:27 #8 0xaaaae5b34fd0 in llvm::FPPassManager::runOnModule(llvm::Module&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1481:16 #9 0xaaaae5b2b7f0 in runOnModule /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1550:27 #10 0xaaaae5b2b7f0 in llvm::legacy::PassManagerImpl::run(llvm::Module&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:44 #11 0xaaaae31ae314 in compileModule(char**, llvm::LLVMContext&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/tools/llc/llc.cpp:756:8 #12 0xaaaae31ac0b8 in main /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/tools/llc/llc.cpp:420:22 #13 0xffffbb03777c (/lib/aarch64-linux-gnu/libc.so.6+0x2777c) (BuildId: fe1fc959438108d405a33383d7c3f00762a5bb93) #14 0xffffbb037854 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x27854) (BuildId: fe1fc959438108d405a33383d7c3f00762a5bb93) #15 0xaaaae3180fec in _start (/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/llc+0x5e90fec) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:214:43 in This revision is now accepted and ready to land.Jun 6 2023, 5:30 PM Comment Actions
Thanks, I'll take a look. The revert needs a cleanup of a test that was added after this patch was commit. I'll take care of that too. Comment Actions Our CI reported that this patch caused code bloat (average ~0.1%) in llvm-test-suite compiled with -Os. We can turn this off when optimizing for size (-Os/-Oz). Comment Actions
Revision Contents
Diff 528974 llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/bswap-bitreverse.ll
llvm/test/CodeGen/RISCV/ctlz-cttz-ctpop.ll
llvm/test/CodeGen/RISCV/div-by-constant.ll
llvm/test/CodeGen/RISCV/div.ll
llvm/test/CodeGen/RISCV/pr56457.ll
llvm/test/CodeGen/RISCV/rv64xtheadbb.ll
llvm/test/CodeGen/RISCV/rv64zbb.ll
llvm/test/CodeGen/RISCV/rvv/bitreverse-sdnode.ll
llvm/test/CodeGen/RISCV/rvv/bitreverse-vp.ll
llvm/test/CodeGen/RISCV/rvv/ctlz-sdnode.ll
llvm/test/CodeGen/RISCV/rvv/ctlz-vp.ll
llvm/test/CodeGen/RISCV/rvv/ctpop-sdnode.ll
llvm/test/CodeGen/RISCV/rvv/ctpop-vp.ll
llvm/test/CodeGen/RISCV/rvv/cttz-sdnode.ll
llvm/test/CodeGen/RISCV/rvv/cttz-vp.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-bitreverse-vp.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-bitreverse.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-ctlz-vp.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-ctlz.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-ctpop-vp.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-ctpop.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-cttz-vp.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-cttz.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll
llvm/test/CodeGen/RISCV/sextw-removal.ll
llvm/test/CodeGen/RISCV/split-udiv-by-constant.ll
llvm/test/CodeGen/RISCV/split-urem-by-constant.ll
llvm/test/CodeGen/RISCV/srem-seteq-illegal-types.ll
|
This should be ADD